Class: RVM::Functions::Get

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

Overview

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

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

Constant Summary collapse

FUNCTION_MAP =
{
  RVM::Classes::List => RVM::Functions::At,
  RVM::Classes::Association => RVM::Functions::AssocGet
}

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



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

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



62
63
64
# File 'lib/rvm/functions/collection/get.rb', line 62

def signature
  [:any]
end