Class: Expressionist::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/expressionist/function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argsObject (readonly)

Returns the value of attribute args.



7
8
9
# File 'lib/expressionist/function.rb', line 7

def args
  @args
end

#nameObject (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_aObject



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_sObject



25
26
27
# File 'lib/expressionist/function.rb', line 25

def to_s
  "#{name}(#{args.map(&to_s).join(', ')})"
end