Class: Iba::MethodCallExpression
- Inherits:
-
Object
- Object
- Iba::MethodCallExpression
- Defined in:
- lib/iba.rb
Instance Attribute Summary collapse
-
#_args ⇒ Object
readonly
Returns the value of attribute _args.
-
#_method ⇒ Object
readonly
Returns the value of attribute _method.
-
#_reciever ⇒ Object
readonly
Returns the value of attribute _reciever.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #_to_s ⇒ Object
-
#initialize(reciever, methodname, args) ⇒ MethodCallExpression
constructor
A new instance of MethodCallExpression.
- #method_is_operator? ⇒ Boolean
- #method_missing(method, *args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(reciever, methodname, args) ⇒ MethodCallExpression
Returns a new instance of MethodCallExpression.
108 109 110 111 112 |
# File 'lib/iba.rb', line 108 def initialize reciever, methodname, args @_reciever = reciever @_method = methodname @_args = args.map { |a| _wrap(a) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
137 138 139 140 |
# File 'lib/iba.rb', line 137 def method_missing method, *args super if method.to_s =~ /^_/ MethodCallExpression.new self, method, args end |
Instance Attribute Details
#_args ⇒ Object (readonly)
Returns the value of attribute _args.
106 107 108 |
# File 'lib/iba.rb', line 106 def _args @_args end |
#_method ⇒ Object (readonly)
Returns the value of attribute _method.
106 107 108 |
# File 'lib/iba.rb', line 106 def _method @_method end |
#_reciever ⇒ Object (readonly)
Returns the value of attribute _reciever.
106 107 108 |
# File 'lib/iba.rb', line 106 def _reciever @_reciever end |
Instance Method Details
#==(other) ⇒ Object
150 151 152 |
# File 'lib/iba.rb', line 150 def == other method_missing :==, other end |
#_to_s ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/iba.rb', line 114 def _to_s rcv = @_reciever._to_s args = @_args.map { |a| a.respond_to?(:_to_s) ? a._to_s : a.to_s } if @_method == :[] "#{rcv}[#{args[0]}]" elsif method_is_operator? case @_args.length when 0 "#{@_method.to_s.sub(/@$/, '')}#{rcv}" when 1 "(#{rcv} #{@_method} #{args.first})" else raise NotImplementedError end else str = rcv == '' ? '' : "#{rcv}." str << @_method.to_s str << "(#{args.join(', ')})" unless @_args.empty? str end end |
#method_is_operator? ⇒ Boolean
142 143 144 |
# File 'lib/iba.rb', line 142 def method_is_operator? @_method.to_s !~ /^[a-z]/ end |
#to_s ⇒ Object
146 147 148 |
# File 'lib/iba.rb', line 146 def to_s method_missing :to_s end |