Class: Dict
- Inherits:
-
Object
- Object
- Dict
- Defined in:
- lib/mealib/dict.rb
Overview
Базовый класс для словарей из Dicts.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id, index) ⇒ Dict
constructor
A new instance of Dict.
Constructor Details
#initialize(id, index) ⇒ Dict
Returns a new instance of Dict.
6 7 8 9 |
# File 'lib/mealib/dict.rb', line 6 def initialize(id, index) @id = id @index = index end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/mealib/dict.rb', line 4 def id @id end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
4 5 6 |
# File 'lib/mealib/dict.rb', line 4 def index @index end |
Class Method Details
.all ⇒ Object
11 12 13 |
# File 'lib/mealib/dict.rb', line 11 def self.all constants.select { |const| (const_get const).class != Array }.map { |const| const_get const } # пока я не добавил константы типа ALL, работала эта строка: constants.map { |const| const_get const } end |
.find(id) ⇒ Object
15 16 17 |
# File 'lib/mealib/dict.rb', line 15 def self.find(id) all.select { |const| const.id == id.to_i }.first end |
.find_by_index(index) ⇒ Object
19 20 21 |
# File 'lib/mealib/dict.rb', line 19 def self.find_by_index(index) all.select { |const| const.index == index }.first end |
.where(ids) ⇒ Object
23 24 25 |
# File 'lib/mealib/dict.rb', line 23 def self.where(ids) all.select { |const| ids.include?(const.id) } end |