Class: Localize::Translation
- Inherits:
-
Object
- Object
- Localize::Translation
- Defined in:
- lib/localize.rb
Instance Method Summary collapse
-
#initialize(hash) ⇒ Translation
constructor
A new instance of Translation.
- #method_missing(name, *params) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Translation
Returns a new instance of Translation.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/localize.rb', line 117 def initialize(hash) hash.each_pair do |key, value| value = Translation.new(value) if value.is_a?(Hash) key = key.to_s instance_variable_set("@#{key}", value) self.class.class_eval do define_method("#{key}") do |*args| str = instance_variable_get("@#{key}") if args.length > 0 _interpolate(str, args) else str end end end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *params) ⇒ Object
135 136 137 |
# File 'lib/localize.rb', line 135 def method_missing(name, *params) MissString.new('Translation missing: '+name.to_s) end |