Class: Cliches::Definition
- Inherits:
-
Object
- Object
- Cliches::Definition
- Defined in:
- lib/cliches/definition.rb
Overview
A class that holds the basic definition of a cliche.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.find(name) ⇒ Object
Finds the definition with a given
name
.
Instance Method Summary collapse
-
#as(value) ⇒ Object
Set the value of a definition as being
value
. -
#initialize(name) ⇒ Definition
constructor
Initialize a cliche with the given
name
and set its value to an empty hash. -
#register ⇒ Object
Registers a definition.
Constructor Details
#initialize(name) ⇒ Definition
Initialize a cliche with the given name
and set its value to an empty hash.
name
will be converted to a symbol
15 16 17 18 |
# File 'lib/cliches/definition.rb', line 15 def initialize(name) @name = name.to_sym @value = {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/cliches/definition.rb', line 9 def name @name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/cliches/definition.rb', line 10 def value @value end |
Class Method Details
.find(name) ⇒ Object
Finds the definition with a given name
. Returns nil
if it there is none.
26 27 28 |
# File 'lib/cliches/definition.rb', line 26 def self.find(name) definitions[name.to_sym] end |
Instance Method Details
#as(value) ⇒ Object
Set the value of a definition as being value
.
21 22 23 |
# File 'lib/cliches/definition.rb', line 21 def as(value) @value = value end |
#register ⇒ Object
Registers a definition. This will override any existing definition with the same name.
31 32 33 34 |
# File 'lib/cliches/definition.rb', line 31 def register self.class.definitions[name] = self self end |