Class: RVM::Functions::Size

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

Overview

The Size function is a generalized function for determin the number of elements for classes that store collections of more then one element. Currently List and Associations are supported.

It takes one or no arguments, if no arguments are passed it expects :self to be set to a valid class, otherwis the first argument is queried for it’s size.

Constant Summary collapse

COLLECTION_CLASSES =
[
  RVM::Classes::List,
  RVM::Classes::Association
]

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



41
42
43
44
45
46
47
48
49
# File 'lib/rvm/functions/collection/size.rb', line 41

def execute params, env
  if COLLECTION_CLASSES.include?((this = env.read_var_val(:self)).class) and params.empty?
    RVM::Classes[:number].new(this.size)
  elsif params.length == 1
    RVM::Classes[:number].new(params[0].size)
  else
    RVM::Classes[:error].new(1,"FUNCTION (#{self}) EXPECTS 1 or 0 ARGUMENTS BUT GOT #{params.length}")
  end
end

.signatureObject



50
51
52
# File 'lib/rvm/functions/collection/size.rb', line 50

def signature
  [:any]
end