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.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/bel/language.rb', line 134

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.



133
134
135
# File 'lib/bel/language.rb', line 133

def arguments
  @arguments
end

#fxObject (readonly)

Returns the value of attribute fx.



133
134
135
# File 'lib/bel/language.rb', line 133

def fx
  @fx
end

Instance Method Details

#<=>(other) ⇒ Object



154
155
156
157
158
159
160
# File 'lib/bel/language.rb', line 154

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



149
150
151
152
# File 'lib/bel/language.rb', line 149

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

#to_sObject



162
163
164
165
# File 'lib/bel/language.rb', line 162

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