Class: Value::Values
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#comparable ⇒ Object
readonly
Returns the value of attribute comparable.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#splat ⇒ Object
readonly
Returns the value of attribute splat.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #each {|splat| ... } ⇒ Object
-
#initialize(*values) ⇒ Values
constructor
A new instance of Values.
Constructor Details
#initialize(*values) ⇒ Values
Returns a new instance of Values.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/value/values.rb', line 6 def initialize(*values) = Hash === values.last ? values.pop : {} values.pop if @block = values.last.to_s.start_with?('&') ? values.last.to_s[1..-1].to_sym : nil values.pop if @splat = (values.last and values.last.to_s.start_with?('*')) ? values.last.to_s[1..-1].to_sym : nil required, optional = values.partition{ |e| not(Array === e) } @required = required.map(&:to_sym) @optional = optional.map{ |e| [e.first.to_sym, e.last] } all = to_a @comparable = Array === [:comparable] ? [:comparable].each{ |e| raise ArgumentError, '%p is not among comparable members %s' % [e, all.map(&:inspect).join(', ')] unless all.include?(e) } : all end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
43 44 45 |
# File 'lib/value/values.rb', line 43 def block @block end |
#comparable ⇒ Object (readonly)
Returns the value of attribute comparable.
43 44 45 |
# File 'lib/value/values.rb', line 43 def comparable @comparable end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
43 44 45 |
# File 'lib/value/values.rb', line 43 def optional @optional end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
43 44 45 |
# File 'lib/value/values.rb', line 43 def required @required end |
#splat ⇒ Object (readonly)
Returns the value of attribute splat.
43 44 45 |
# File 'lib/value/values.rb', line 43 def splat @splat end |
Instance Method Details
#==(other) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/value/values.rb', line 35 def ==(other) self.class == other.class and required == other.required and optional == other.optional and splat == other.splat and block == other.block end |
#each {|splat| ... } ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/value/values.rb', line 22 def each return enum_for(__method__) unless block_given? required.each do |value| yield value end optional.each do |value, _| yield value end yield splat if splat yield block if block self end |