Class: OpenStruct
- Inherits:
-
Object
- Object
- OpenStruct
- Includes:
- Everythingrb::InspectQuotable
- Defined in:
- lib/everythingrb/ostruct.rb
Overview
Extensions to Ruby’s OpenStruct class
Provides:
-
#map, #filter_map: Enumeration methods for OpenStruct entries
-
#join_map: Combine filter_map and join operations
-
#blank?, #present?: ActiveSupport integrations when available
-
#in_quotes, #with_quotes: Wrap struct in quotes
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Checks if the OpenStruct has no attributes.
-
#filter_map {|key, value| ... } ⇒ Array, Enumerator
Maps over OpenStruct entries and returns an array without nil values.
-
#join_map(join_with = "") {|key, value| ... } ⇒ String
Combines filter_map and join operations.
-
#map {|key, value| ... } ⇒ Array, Enumerator
Maps over OpenStruct entries and returns an array.
-
#present? ⇒ Boolean
Checks if the OpenStruct has any attributes.
-
#to_ostruct ⇒ self
Returns self (identity method for consistent interfaces).
Methods included from Everythingrb::InspectQuotable
Instance Method Details
#blank? ⇒ Boolean
Only available when ActiveSupport is loaded
Checks if the OpenStruct has no attributes
30 31 32 |
# File 'lib/everythingrb/ostruct.rb', line 30 def blank? @table.blank? end |
#filter_map {|key, value| ... } ⇒ Array, Enumerator
Maps over OpenStruct entries and returns an array without nil values
78 79 80 81 82 |
# File 'lib/everythingrb/ostruct.rb', line 78 def filter_map(&block) return enum_for(:filter_map) unless block map(&block).compact end |
#join_map(join_with = "") {|key, value| ... } ⇒ String
Combines filter_map and join operations
105 106 107 108 109 |
# File 'lib/everythingrb/ostruct.rb', line 105 def join_map(join_with = "", &block) block = ->(kv_pair) { kv_pair.compact } if block.nil? filter_map(&block).join(join_with) end |
#map {|key, value| ... } ⇒ Array, Enumerator
Maps over OpenStruct entries and returns an array
61 62 63 |
# File 'lib/everythingrb/ostruct.rb', line 61 def map(&) @table.map(&) end |
#present? ⇒ Boolean
Only available when ActiveSupport is loaded
Checks if the OpenStruct has any attributes
41 42 43 |
# File 'lib/everythingrb/ostruct.rb', line 41 def present? @table.present? end |
#to_ostruct ⇒ self
Returns self (identity method for consistent interfaces)
116 117 118 |
# File 'lib/everythingrb/ostruct.rb', line 116 def to_ostruct self end |