Class: Humanoid::Field
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#get(object) ⇒ Object
Used for retrieving the object out of the attributes hash.
-
#initialize(name, options = {}) ⇒ Field
constructor
Create the new field with a name and optional additional options.
-
#set(object) ⇒ Object
Used for setting an object in the attributes hash.
Constructor Details
#initialize(name, options = {}) ⇒ Field
Create the new field with a name and optional additional options. Valid options are :default
Options:
name: The name of the field as a Symbol
. options: A Hash
of options for the field.
Example:
Field.new(:score, :default => 0)
21 22 23 24 25 |
# File 'lib/humanoid/field.rb', line 21 def initialize(name, = {}) @name = name @default = [:default] @type = [:type] || String end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
5 6 7 |
# File 'lib/humanoid/field.rb', line 5 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/humanoid/field.rb', line 5 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/humanoid/field.rb', line 5 def type @type end |
Instance Method Details
#get(object) ⇒ Object
Used for retrieving the object out of the attributes hash.
34 35 36 |
# File 'lib/humanoid/field.rb', line 34 def get(object) type.get(object) end |
#set(object) ⇒ Object
Used for setting an object in the attributes hash. If nil is provided the default will get returned if it exists.
29 30 31 |
# File 'lib/humanoid/field.rb', line 29 def set(object) object.nil? ? default : type.set(object) end |