Class: DotOptions
- Inherits:
-
Object
- Object
- DotOptions
- Defined in:
- lib/dot_options.rb,
lib/dot_options/version.rb
Constant Summary collapse
- VERSION =
'0.1.2'
Instance Attribute Summary collapse
-
#_full_path ⇒ Object
Returns the value of attribute _full_path.
-
#_key ⇒ Object
Returns the value of attribute _key.
-
#_options ⇒ Object
readonly
Returns the value of attribute _options.
-
#_parent ⇒ Object
Returns the value of attribute _parent.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(base_options = nil, &block) ⇒ DotOptions
constructor
A new instance of DotOptions.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(base_options = nil, &block) ⇒ DotOptions
Returns a new instance of DotOptions.
5 6 7 8 9 10 11 12 |
# File 'lib/dot_options.rb', line 5 def initialize( = nil, &block) @_key = nil @_parent = nil @_options = [] @_full_path = [] ( || {}) instance_eval(&block) if block end |
Instance Attribute Details
#_full_path ⇒ Object
Returns the value of attribute _full_path.
3 4 5 |
# File 'lib/dot_options.rb', line 3 def _full_path @_full_path end |
#_key ⇒ Object
Returns the value of attribute _key.
3 4 5 |
# File 'lib/dot_options.rb', line 3 def _key @_key end |
#_options ⇒ Object (readonly)
Returns the value of attribute _options.
2 3 4 |
# File 'lib/dot_options.rb', line 2 def @_options end |
#_parent ⇒ Object
Returns the value of attribute _parent.
3 4 5 |
# File 'lib/dot_options.rb', line 3 def _parent @_parent end |
Instance Method Details
#[](key) ⇒ Object
14 15 16 |
# File 'lib/dot_options.rb', line 14 def [](key) .include?(key.to_sym) ? send(key.to_sym) : nil end |
#inspect ⇒ Object
18 19 20 |
# File 'lib/dot_options.rb', line 18 def inspect "<#{.map { |key| "#{key}: #{send(key).inspect}" }.join(', ')}>" end |
#to_h ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/dot_options.rb', line 26 def to_h .to_h do |key| value = send key value = value.to_h if value.is_a? DotOptions [key, value] end end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/dot_options.rb', line 22 def to_s .map { |key, value| "#{key} = #{value.inspect}" }.join "\n" end |