diff options
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r-- | lib/ostruct.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb index a08561d6c9..c762baa5a5 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -107,7 +107,15 @@ # For all these reasons, consider not using OpenStruct at all. # class OpenStruct - VERSION = "0.5.5" + VERSION = "0.6.0" + + HAS_PERFORMANCE_WARNINGS = begin + Warning[:performance] + true + rescue NoMethodError, ArgumentError + false + end + private_constant :HAS_PERFORMANCE_WARNINGS # # Creates a new OpenStruct object. By default, the resulting OpenStruct @@ -124,6 +132,10 @@ class OpenStruct # data # => #<OpenStruct country="Australia", capital="Canberra"> # def initialize(hash=nil) + if HAS_PERFORMANCE_WARNINGS && Warning[:performance] + warn "OpenStruct use is discouraged for performance reasons", uplevel: 1, category: :performance + end + if hash update_to_values!(hash) else @@ -364,7 +376,7 @@ class OpenStruct end @table.delete(sym) do return yield if block - raise! NameError.new("no field `#{sym}' in #{self}", sym) + raise! NameError.new("no field '#{sym}' in #{self}", sym) end end |