Module: SuperatorMixin
- Defined in:
- lib/superators/macro.rb
Constant Summary collapse
- BINARY_RUBY_OPERATORS =
%w"** * / % + - << >> & | ^ <=> >= <= < > === == =~"
- UNARY_RUBY_OPERATORS =
%w"-@ ~@ +@"
- BINARY_OPERATOR_PATTERN =
BINARY_RUBY_OPERATORS.map { |x| Regexp.escape(x) }.join "|"
- UNARY_OPERATOR_PATTERN =
UNARY_RUBY_OPERATORS.map { |x| Regexp.escape(x) }.join "|"
- UNARY_OPERATOR_PATTERN_WITHOUT_AT_SIGN =
UNARY_OPERATOR_PATTERN.map { |x| x.gsub('@', '') }
- VALID_SUPERATOR =
/^(#{BINARY_OPERATOR_PATTERN})(#{UNARY_OPERATOR_PATTERN_WITHOUT_AT_SIGN})+$/
Instance Method Summary collapse
- #defined_superators ⇒ Object
- #respond_to_superator?(sup) ⇒ Boolean
- #superator_send(sup, operand) ⇒ Object
- #undef_superator(sup) ⇒ Object
Instance Method Details
#defined_superators ⇒ Object
24 25 26 |
# File 'lib/superators/macro.rb', line 24 def defined_superators methods.grep(/superator_definition_/).map { |m| superator_decode(m) } end |
#respond_to_superator?(sup) ⇒ Boolean
20 21 22 |
# File 'lib/superators/macro.rb', line 20 def respond_to_superator?(sup) respond_to? superator_definition_name_for(sup) end |
#superator_send(sup, operand) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/superators/macro.rb', line 12 def superator_send(sup, operand) if respond_to_superator? sup __send__ superator_definition_name_for(sup), operand else raise NoMethodError, "Superator #{sup} has not been defined on #{self.class}" end end |
#undef_superator(sup) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/superators/macro.rb', line 66 def undef_superator(sup) if respond_to_superator?(sup) real_operator = real_operator_from_superator sup real_operator_alias = superator_alias_for sup (class << self; self; end).instance_eval do undef_method superator_definition_name_for(sup) if respond_to? real_operator_alias alias_method real_operator, real_operator_alias if defined_superators.empty? else undef_method real_operator end end else raise NoMethodError, "undefined superator #{sup} for #{self.inspect}:#{self.class}" end end |