Class: BEL::Language::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/bel/language.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fx, *arguments) ⇒ Signature

Returns a new instance of Signature.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bel/language.rb', line 7

def initialize(fx, *arguments)
  @fx = fx
  @arguments = arguments

  dup_hash = {}
  @arguments.each_with_index { |arg, i| (dup_hash[arg] ||= []) << i }
  dup_hash.keep_if { |k, v| v.length > 1 }.values.each do |v|
    first_arg = @arguments[v[0]]
    if F === first_arg
      replace_range = (v.first..v.last)
      @arguments[replace_range] = F.new(first_arg.func_return, true)
    end
  end
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



6
7
8
# File 'lib/bel/language.rb', line 6

def arguments
  @arguments
end

#fxObject (readonly)

Returns the value of attribute fx.



6
7
8
# File 'lib/bel/language.rb', line 6

def fx
  @fx
end

Instance Method Details

#<=>(other) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/bel/language.rb', line 27

def <=>(other)
  return 1 if other.nil?
  return -1 if @fx != other.fx
  return -1 if @arguments.nil? and not other.nil?
  return 1 if not @arguments.nil? and other.nil?
  @arguments <=> other.arguments
end

#==(other) ⇒ Object



22
23
24
25
# File 'lib/bel/language.rb', line 22

def ==(other)
  return false if @fx != other.fx
  @arguments == other.arguments
end

#to_sObject



35
36
37
38
# File 'lib/bel/language.rb', line 35

def to_s
  return_type = FUNCTIONS[@fx][:return_type]
  "#{@fx}(#{@arguments.map(&:to_s) * ','})#{return_type}"
end