Class: LibBin::DataShape
- Inherits:
-
Object
- Object
- LibBin::DataShape
- Defined in:
- lib/libbin/data_types.rb
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
- #first ⇒ Object
-
#initialize(*args) ⇒ DataShape
constructor
A new instance of DataShape.
- #last ⇒ Object
- #method_missing(m, *arg, &block) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(*args) ⇒ DataShape
Returns a new instance of DataShape.
23 24 25 26 27 28 29 30 31 |
# File 'lib/libbin/data_types.rb', line 23 def initialize(*args) if args.length == 2 @range = Range::new(args[0], args[1]) @members = nil else @members = args[0] @range = @members.values.flatten.compact.collect(&:range).reduce { |memo, obj| memo + obj } end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *arg, &block) ⇒ Object
18 19 20 21 |
# File 'lib/libbin/data_types.rb', line 18 def method_missing(m, *arg, &block) return @members[m] if @members && @members[m] super end |
Instance Attribute Details
#members ⇒ Object (readonly)
Returns the value of attribute members.
16 17 18 |
# File 'lib/libbin/data_types.rb', line 16 def members @members end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
15 16 17 |
# File 'lib/libbin/data_types.rb', line 15 def range @range end |
Instance Method Details
#first ⇒ Object
33 34 35 |
# File 'lib/libbin/data_types.rb', line 33 def first @range.first end |
#last ⇒ Object
37 38 39 |
# File 'lib/libbin/data_types.rb', line 37 def last @range.last end |
#size ⇒ Object
41 42 43 |
# File 'lib/libbin/data_types.rb', line 41 def size @range.size end |