Class: Blacklight::OpenStructWithHashAccess
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Blacklight::OpenStructWithHashAccess
show all
- Defined in:
- lib/blacklight/open_struct_with_hash_access.rb
Overview
An OpenStruct that responds to common Hash methods
Instance Method Summary
collapse
Instance Method Details
#deep_dup ⇒ Object
52
53
54
|
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 52
def deep_dup
self.class.new @table.deep_dup
end
|
56
57
58
|
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 56
def deep_transform_values(&method)
self.class.new @table.deep_transform_values(&method)
end
|
Merge the values of this OpenStruct with another OpenStruct or Hash
36
37
38
|
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 36
def merge other_hash
self.class.new to_h.merge((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
end
|
Merge the values of another OpenStruct or Hash into this object
44
45
46
|
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 44
def merge! other_hash
@table.merge!((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
end
|
#reverse_merge(other_hash) ⇒ Object
48
49
50
|
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 48
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 ⇒ Object
19
20
21
|
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 19
def select(...)
self.class.new to_h.select(...)
end
|
#sort_by ⇒ Object
23
24
25
|
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 23
def sort_by(...)
self.class.new to_h.sort_by(...).to_h
end
|
#sort_by! ⇒ Object
27
28
29
30
|
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 27
def sort_by!(...)
replace to_h.sort_by(...).to_h
self
end
|
#to_h ⇒ Hash
15
16
17
|
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 15
def to_h
@table
end
|
#try(method_name = nil, *args, &block) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/blacklight/open_struct_with_hash_access.rb', line 60
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
|