lib/clamp/messages.rb in clamp-1.0.1 vs lib/clamp/messages.rb in clamp-1.1.0
- old
+ new
@@ -4,12 +4,12 @@
def messages=(new_messages)
messages.merge!(new_messages)
end
- def message(key, options={})
- format_string(messages.fetch(key), options)
+ def message(key, options = {})
+ format(messages.fetch(key), options)
end
def clear_messages!
init_default_messages
end
@@ -28,41 +28,18 @@
:no_value_provided => "no value provided",
:usage_heading => "Usage",
:parameters_heading => "Parameters",
:subcommands_heading => "Subcommands",
:options_heading => "Options"
- }
+ }.freeze
def messages
- unless defined?(@messages)
- init_default_messages
- end
+ init_default_messages unless defined?(@messages)
@messages
end
def init_default_messages
- @messages = DEFAULTS.clone
- end
-
- begin
-
- ("%{foo}" % {:foo => "bar"}) # test Ruby 1.9 string interpolation
-
- def format_string(format, params = {})
- format % params
- end
-
- rescue ArgumentError
-
- # string formatting for ruby 1.8
- def format_string(format, params = {})
- array_params = format.scan(/%[<{]([^>}]*)[>}]/).collect do |name|
- name = name[0]
- params[name.to_s] || params[name.to_sym]
- end
- format.gsub(/%[<]([^>]*)[>]/, '%').gsub(/%[{]([^}]*)[}]/, '%s') % array_params
- end
-
+ @messages = DEFAULTS.dup
end
end
extend Messages