Class: Most::Options
Instance Method Summary collapse
- #[](key, *args) ⇒ Object
- #has_any?(*args) ⇒ Boolean
-
#initialize(hash = nil) ⇒ Options
constructor
A new instance of Options.
Methods inherited from Hash
Constructor Details
#initialize(hash = nil) ⇒ Options
Returns a new instance of Options.
30 31 32 |
# File 'lib/most/structures/types/options.rb', line 30 def initialize(hash = nil) super(); replace(hash) unless hash.nil? end |
Instance Method Details
#[](key, *args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/most/structures/types/options.rb', line 34 def [](key, *args) if key.is_a?(Array) args.unshift(*key[1..-1]) key = key.first end result = super(key) args.each do |item| break if result.nil? result = result.try(:[], item) end result end |
#has_any?(*args) ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/most/structures/types/options.rb', line 50 def has_any?(*args) result = nil args.each do |item| if item.is_a?(Array) result = self[*item] else result = self[item] end break unless result.nil? end result end |