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.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/bel/language.rb', line 144

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.



143
144
145
# File 'lib/bel/language.rb', line 143

def arguments
  @arguments
end

#fxObject (readonly)

Returns the value of attribute fx.



143
144
145
# File 'lib/bel/language.rb', line 143

def fx
  @fx
end

Instance Method Details

#<=>(other) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/bel/language.rb', line 164

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



159
160
161
162
# File 'lib/bel/language.rb', line 159

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

#to_sObject



172
173
174
175
# File 'lib/bel/language.rb', line 172

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