Class: Basic101::RndFunction
- Defined in:
- lib/basic101/rnd_function.rb
Instance Method Summary collapse
- #call(runtime, args) ⇒ Object
-
#initialize ⇒ RndFunction
constructor
A new instance of RndFunction.
- #name ⇒ Object
Methods inherited from Function
Constructor Details
#initialize ⇒ RndFunction
Returns a new instance of RndFunction.
7 8 9 |
# File 'lib/basic101/rnd_function.rb', line 7 def initialize @rand = 0 end |
Instance Method Details
#call(runtime, args) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/basic101/rnd_function.rb', line 15 def call(runtime, args) check_args args, [BasicNumeric] new_number = args.first.eval(runtime).to_f > 0 if new_number @rand = runtime.rand end BasicFloat.new(@rand) end |
#name ⇒ Object
11 12 13 |
# File 'lib/basic101/rnd_function.rb', line 11 def name 'RND' end |