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.
5 6 7 |
# File 'lib/basic101/rnd_function.rb', line 5 def initialize @rand = 0 end |
Instance Method Details
#call(runtime, args) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/basic101/rnd_function.rb', line 13 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
9 10 11 |
# File 'lib/basic101/rnd_function.rb', line 9 def name 'RND' end |