Class: Nydp::Builtin::ToInteger

Inherits:
Object
  • Object
show all
Includes:
Base, Singleton
Defined in:
lib/nydp/builtin/to_integer.rb

Instance Method Summary collapse

Methods included from Base

#builtin_invoke_1, #builtin_invoke_3, #builtin_invoke_4, #handle_error, #inspect, #invoke, #invoke_1, #invoke_2, #invoke_3, #invoke_4, #name, #nydp_type, #to_s

Methods included from Helper

#cons, #list, #literal?, #pair?, #sig, #sym, #sym?

Methods included from Converter

#n2r, #r2n

Instance Method Details

#builtin_invoke(vm, args) ⇒ Object



19
20
21
# File 'lib/nydp/builtin/to_integer.rb', line 19

def builtin_invoke vm, args
  builtin_invoke_2 vm, args.car
end

#builtin_invoke_2(vm, arg) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/nydp/builtin/to_integer.rb', line 5

def builtin_invoke_2 vm, arg
  arg = n2r arg

  i = if arg.respond_to? :to_i
        arg.to_i
      elsif arg.respond_to? :to_time
        arg.to_time.to_i
      else
        arg.to_s.to_i
      end

  vm.push_arg r2n i
end