Class: EacRubyUtils::ObjectsTable
- Defined in:
- lib/eac_ruby_utils/objects_table.rb
Defined Under Namespace
Classes: BY_PARSER_PARSED_STRUCT
Constant Summary collapse
- BY_PARSER =
::EacRubyUtils::RegexpParser.new(/\Aby_([^!?]+)(!)?\z/) do |m| BY_PARSER_PARSED_STRUCT.new(m[1], "by_attribute#{'!' if m[2].present?}") end
Instance Method Summary collapse
- #by_attribute(name, value) ⇒ Object?
- #by_attribute!(name, value) ⇒ Object
- #method_missing(method_name) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Method Details
#by_attribute(name, value) ⇒ Object?
17 18 19 |
# File 'lib/eac_ruby_utils/objects_table.rb', line 17 def by_attribute(name, value) objects.find { |e| e.send(name) == value } end |
#by_attribute!(name, value) ⇒ Object
24 25 26 27 |
# File 'lib/eac_ruby_utils/objects_table.rb', line 24 def by_attribute!(name, value) by_attribute(name, value) || raise(::ArgumentError, "No item found with attribute #{name}=#{value}") end |