Class: Parameters::Param
Direct Known Subclasses
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Description of parameter.
-
#name ⇒ Object
readonly
Name of parameter.
-
#type ⇒ Object
readonly
Enforced type of the parameter.
Instance Method Summary collapse
-
#coerce(value) ⇒ Object
Coerces the value into the param type.
-
#initialize(name, type = nil, description = nil) ⇒ Param
constructor
Creates a new Param object.
Constructor Details
#initialize(name, type = nil, description = nil) ⇒ Param
Creates a new Param object.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/parameters/param.rb', line 29 def initialize(name,type=nil,description=nil) @name = name.to_sym @type = if (type.kind_of?(Types::Type)) || (type.kind_of?(Class) && (type < Types::Type)) type else Types[type] end @description = description end |
Instance Attribute Details
#description ⇒ Object (readonly)
Description of parameter
13 14 15 |
# File 'lib/parameters/param.rb', line 13 def description @description end |
#name ⇒ Object (readonly)
Name of parameter
7 8 9 |
# File 'lib/parameters/param.rb', line 7 def name @name end |
#type ⇒ Object (readonly)
Enforced type of the parameter
10 11 12 |
# File 'lib/parameters/param.rb', line 10 def type @type end |
Instance Method Details
#coerce(value) ⇒ Object
Coerces the value into the param type.
52 53 54 55 56 57 58 |
# File 'lib/parameters/param.rb', line 52 def coerce(value) if (value.nil? || (@type === value)) value else @type.coerce(value) end end |