Class: RVM::Functions::Set

Inherits:
Function show all
Defined in:
lib/rvm/functions/collection/set.rb

Overview

The Set function is a generalized function for setting elements of classes that store collections of more then one element. Currently List and Associations are supported.

It takes trhee or two argument, if only two argument it passed the first is used as the key, the second as value, and the :sefl variable must be set. If three arguments are passed the first is expected to be the collection, the second to be the key and the thrid is used as value to set

Constant Summary collapse

FUNCTION_MAP =
{
  RVM::Classes::List => RVM::Functions::SetAt,
  Classes::Association => RVM::Functions::AssocSet
}

Class Method Summary collapse

Methods inherited from Function

call, data_type, execargs, method_missing

Methods included from Plugin

#helper, #included, #plugin_host, #plugin_id, #register_for

Class Method Details

.execute(params, env) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rvm/functions/collection/set.rb', line 45

def execute params, env
  if params.length == 2
    if fun = FUNCTION_MAP[params.first.class]
      fun.execute(params, env)
    else
      RVM::Classes[:error].new(1, "FUNCTION (#{self.class}) does not accept #{params.first.class}")
    end
  elsif params.length == 1 and FUNCTION_MAP.include?((this = env.read_var_val(:self)).class)
    if fun = FUNCTION_MAP[this]
      fun.execute(params, env)
    else
      RVM::Classes[:error].new(1, "FUNCTION (#{self.class}) does not accept #{thiss.class}")
    end         
  else
    RVM::Classes[:error].new(1, "FUNCTION (#{self.class}) EXPECTS 2 or 1 ARGUMENTS BUT GOT #{params.length}")
  end
end

.signatureObject



63
64
65
# File 'lib/rvm/functions/collection/set.rb', line 63

def signature
  [:any]
end