class Blacklight::OpenStructWithHashAccess
An OpenStruct that responds to common Hash methods
Public Instance Methods
deep_dup()
click to toggle source
# File lib/blacklight/open_struct_with_hash_access.rb, line 51 def deep_dup self.class.new @table.deep_dup end
merge(other_hash)
click to toggle source
Merge the values of this OpenStruct with another OpenStruct or Hash @param [Hash,#to_h] other_hash @return [OpenStructWithHashAccess] a new instance of an OpenStructWithHashAccess
# 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)
click to toggle source
Merge the values of another OpenStruct or Hash into this object @param [Hash,#to_h] other_hash @return [OpenStructWithHashAccess] a new instance of an OpenStructWithHashAccess
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
Expose the internal hash @return [Hash]
# File lib/blacklight/open_struct_with_hash_access.rb, line 14 def to_h @table end
try(method_name = nil, *args) { |self| ... }
click to toggle source
Ported from Rails 6 to fix an incompatibility with ostruct
# File lib/blacklight/open_struct_with_hash_access.rb, line 57 def try(method_name = nil, *args, &block) if method_name.nil? && block_given? if b.arity.zero? instance_eval(&block) else yield self end elsif respond_to?(method_name) public_send(method_name, *args, &b) end end