Class: Cliches::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/cliches/definition.rb

Overview

A class that holds the basic definition of a cliche.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/cliches/definition.rb', line 9

def name
  @name
end

#valueObject (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

#registerObject

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