Class: Blacklight::OpenStructWithHashAccess
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Blacklight::OpenStructWithHashAccess
- Defined in:
- lib/blacklight/open_struct_with_hash_access.rb
Overview
An OpenStruct that responds to common Hash methods
Direct Known Subclasses
Configuration, Configuration::Field, Configuration::ToolConfig, Configuration::ViewConfig, NestedOpenStructWithHashAccess
Instance Method Summary collapse
- #deep_dup ⇒ Object
-
#merge(other_hash) ⇒ OpenStructWithHashAccess
Merge the values of this OpenStruct with another OpenStruct or Hash.
-
#merge!(other_hash) ⇒ OpenStructWithHashAccess
Merge the values of another OpenStruct or Hash into this object.
- #reverse_merge(other_hash) ⇒ Object
- #select(*args, &block) ⇒ Object
- #sort_by(*args, &block) ⇒ Object
- #sort_by!(*args, &block) ⇒ Object
-
#to_h ⇒ Hash
Expose the internal hash.
Instance Method Details
#deep_dup ⇒ Object
51 52 53 |
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 51 def deep_dup self.class.new @table.deep_dup end |
#merge(other_hash) ⇒ OpenStructWithHashAccess
Merge the values of this OpenStruct with another OpenStruct or Hash
35 36 37 |
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 35 def merge other_hash self.class.new to_h.merge((other_hash if other_hash.is_a? Hash) || other_hash.to_h) end |
#merge!(other_hash) ⇒ OpenStructWithHashAccess
Merge the values of another OpenStruct or Hash into this object
43 44 45 |
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 43 def merge! other_hash @table.merge!((other_hash if other_hash.is_a? Hash) || other_hash.to_h) end |
#reverse_merge(other_hash) ⇒ Object
47 48 49 |
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 47 def reverse_merge(other_hash) self.class.new to_h.reverse_merge((other_hash if other_hash.is_a? Hash) || other_hash.to_h) end |
#select(*args, &block) ⇒ Object
18 19 20 |
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 18 def select *args, &block self.class.new to_h.select(*args, &block) end |
#sort_by(*args, &block) ⇒ Object
22 23 24 |
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 22 def sort_by *args, &block self.class.new Hash[to_h.sort_by(*args, &block)] end |
#sort_by!(*args, &block) ⇒ Object
26 27 28 29 |
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 26 def sort_by! *args, &block replace Hash[to_h.sort_by(*args, &block)] self end |
#to_h ⇒ Hash
Expose the internal hash
14 15 16 |
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 14 def to_h @table end |