Top Level Namespace

Defined Under Namespace

Modules: Connie

Instance Method Summary collapse

Instance Method Details

#Connie(argument, options = {}) ⇒ Object

The shorthand method to use connie Accepts three kinds of arguments:

1) String

Connie parses the string replacing the :dictionary.format bits of string with random
results from it's dictionaries

2) Symbols

Uses the symbol to pick the dictionary to return and eventually calls the format on 
it.

3) Arrays

As a form of convenience Connie picks a random element out of the array passed


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/connie.rb', line 46

def Connie(argument, options={})
  case argument
  when String
    Connie::Parser.process(argument)
  when Symbol
    argument = argument.to_s.split('.').map &:to_sym
    
    dictionary = Connie[argument.first]
    
    if argument[1]
      dictionary.send argument[1], options
    else
      dictionary
    end
  when Array
    argument[rand(argument.size)]
  when Range
    rand(argument.max-argument.min+1) + argument.min
  else
    raise ArgumentError, 'Connie\'s shorthand expects a string to parse or a symbol or an array'
  end
end

#Connie?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/connie.rb', line 69

def Connie?
  [true,false][rand 2]
end