Class: Nydp::Builtin::RandomString

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

Constant Summary collapse

RANDOM_CHARS =
["A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z","2","3","4","5","6","7","8","9"]

Instance Method Summary collapse

Methods included from Base

#builtin_invoke_1, #builtin_invoke_2, #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



6
7
8
9
10
# File 'lib/nydp/builtin/random_string.rb', line 6

def builtin_invoke vm, args
  length = args.car unless Nydp::NIL.is?(args)
  s = (0...(length || 10)).inject("") {|a,i| a << RANDOM_CHARS[rand(RANDOM_CHARS.size)] }
  vm.push_arg s
end