Class: OpenStruct
- Inherits:
-
Object
- Object
- OpenStruct
- Defined in:
- lib/everythingrb/core/ostruct.rb
Overview
Extensions to Ruby’s OpenStruct class
These additions make OpenStructs way more flexible with enumeration methods and ActiveSupport integration.
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).
Instance Method Details
#blank? ⇒ Boolean
Checks if the OpenStruct has no attributes
21 22 23 |
# File 'lib/everythingrb/core/ostruct.rb', line 21 def blank? @table.blank? end |
#filter_map {|key, value| ... } ⇒ Array, Enumerator
Maps over OpenStruct entries and returns an array without nil values
67 68 69 70 71 |
# File 'lib/everythingrb/core/ostruct.rb', line 67 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
94 95 96 97 98 |
# File 'lib/everythingrb/core/ostruct.rb', line 94 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
50 51 52 |
# File 'lib/everythingrb/core/ostruct.rb', line 50 def map(&) @table.map(&) end |
#present? ⇒ Boolean
Checks if the OpenStruct has any attributes
30 31 32 |
# File 'lib/everythingrb/core/ostruct.rb', line 30 def present? @table.present? end |
#to_ostruct ⇒ self
Returns self (identity method for consistent interfaces)
105 106 107 |
# File 'lib/everythingrb/core/ostruct.rb', line 105 def to_ostruct self end |