Class: PromptLists::List
- Inherits:
-
Object
- Object
- PromptLists::List
- Defined in:
- lib/prompt_lists.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#sublist_names ⇒ Object
readonly
Returns the value of attribute sublist_names.
Instance Method Summary collapse
-
#initialize(list_name, sublist_names) ⇒ List
constructor
A new instance of List.
- #method_missing(method_name, *args) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(list_name, sublist_names) ⇒ List
Returns a new instance of List.
10 11 12 13 |
# File 'lib/prompt_lists.rb', line 10 def initialize(list_name, sublist_names) @id = list_name.to_sym @sublist_names = sublist_names end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/prompt_lists.rb', line 15 def method_missing(method_name, *args) sublist = @sublist_names.find { |sublist| sublist == method_name } if sublist sublist_filename = method_name.to_s.gsub(/_/, "-") path = File.("../lists/#{@id}/#{sublist_filename}.yml", __dir__) Sublist.new(path) else super end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/prompt_lists.rb', line 8 def id @id end |
#sublist_names ⇒ Object (readonly)
Returns the value of attribute sublist_names.
8 9 10 |
# File 'lib/prompt_lists.rb', line 8 def sublist_names @sublist_names end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
26 27 28 29 |
# File 'lib/prompt_lists.rb', line 26 def respond_to_missing?(method_name, include_private = false) sublist = @sublist_names.find { |sublist| sublist == method_name } sublist || super end |