Module: GOBL::Extensions::I18n::ValueKeysHelper

Included in:
I18n::String
Defined in:
lib/gobl/extensions/i18n/value_keys_helper.rb

Overview

Additional methods for the generated I18n::String class

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Enables dynamic getter methods for the mapped keys.

Examples:

str = GOBL::I18n::String.new(en: 'Name', es: 'Nombre')
str.en #=> "Name"
str.es #=> "Nombre"


14
15
16
17
18
19
20
# File 'lib/gobl/extensions/i18n/value_keys_helper.rb', line 14

def method_missing(method_name, *args, &block)
  if _map.key?(method_name) || _map.key?(method_name.to_s)
    _map[method_name] || _map[method_name.to_s]
  else
    super
  end
end

Instance Method Details

#respond_to_missing?(method_name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


23
24
25
# File 'lib/gobl/extensions/i18n/value_keys_helper.rb', line 23

def respond_to_missing?(method_name, *)
  _map.key?(method_name) || _map.key?(method_name.to_s) || super
end