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.



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

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.



4
5
6
# File 'lib/bel/language.rb', line 4

def arguments
  @arguments
end

#fxObject (readonly)

Returns the value of attribute fx.



4
5
6
# File 'lib/bel/language.rb', line 4

def fx
  @fx
end

Instance Method Details

#<=>(other) ⇒ Object



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

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



20
21
22
23
# File 'lib/bel/language.rb', line 20

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

#to_sObject



33
34
35
36
# File 'lib/bel/language.rb', line 33

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