Class: Expressionist::Function
- Inherits:
-
Object
- Object
- Expressionist::Function
- Defined in:
- lib/expressionist/function.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, *args) ⇒ Function
constructor
A new instance of Function.
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, *args) ⇒ Function
Returns a new instance of Function.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/expressionist/function.rb', line 9 def initialize(name, *args) if name.kind_of?(Array) && args.length == 0 @name = name[0] @args = name[1..-1].map do |arg| arg.kind_of?(Array) ? Function.new(arg) : arg end else @name = name @args = args end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
7 8 9 |
# File 'lib/expressionist/function.rb', line 7 def args @args end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/expressionist/function.rb', line 7 def name @name end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 |
# File 'lib/expressionist/function.rb', line 29 def ==(other) self.class == other.class && other.name == self.name && other.args == self.args end |
#to_a ⇒ Object
21 22 23 |
# File 'lib/expressionist/function.rb', line 21 def to_a [name] + args.map { |arg| arg.kind_of?(Function) ? arg.to_a : arg } end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/expressionist/function.rb', line 25 def to_s "#{name}(#{args.map(&to_s).join(', ')})" end |