Class: RandomNumber

Inherits:
Dynasnip show all
Defined in:
lib/vanilla/dynasnips/rand.rb

Instance Attribute Summary

Attributes inherited from Vanilla::Renderers::Base

#app

Instance Method Summary collapse

Methods inherited from Dynasnip

all, attribute, build_snip, #method_missing, persist!, persist_all!, snip_attributes, snip_name, usage

Methods inherited from Vanilla::Renderers::Base

escape_curly_braces, #include_snips, #initialize, #prepare, #process_text, #raw_content, render, #render, #render_without_including_snips, snip_regexp

Constructor Details

This class inherits a constructor from Vanilla::Renderers::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Dynasnip

Instance Method Details

#handle(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vanilla/dynasnips/rand.rb', line 14

def handle(*args)
  min = 1
  max = 100
  max = args[0] if args.length == 1
  if args.length == 2
    min = args[0]
    max = args[1]
  end
  # arguments come in as strings, so we need to convert them.
  min = min.to_i
  max = max.to_i
  (rand(max-min) + min)
end