lib/ostruct.rb in ostruct-0.5.0 vs lib/ostruct.rb in ostruct-0.5.1

- old
+ new

@@ -91,25 +91,25 @@ # o = OpenStruct.new # o.methods # => [:to_h, :marshal_load, :marshal_dump, :each_pair, ... # o.methods = [:foo, :bar] # o.methods # => [:foo, :bar] # -# To help remedy clashes, OpenStruct uses only protected/private methods ending with `!` -# and defines aliases for builtin public methods by adding a `!`: +# To help remedy clashes, OpenStruct uses only protected/private methods ending with <code>!</code> +# and defines aliases for builtin public methods by adding a <code>!</code>: # # o = OpenStruct.new(make: 'Bentley', class: :luxury) # o.class # => :luxury # o.class! # => OpenStruct # -# It is recommended (but not enforced) to not use fields ending in `!`; +# It is recommended (but not enforced) to not use fields ending in <code>!</code>; # Note that a subclass' methods may not be overwritten, nor can OpenStruct's own methods -# ending with `!`. +# ending with <code>!</code>. # # For all these reasons, consider not using OpenStruct at all. # class OpenStruct - VERSION = "0.5.0" + VERSION = "0.5.1" # # Creates a new OpenStruct object. By default, the resulting OpenStruct # object will have no attributes. # @@ -277,11 +277,11 @@ # # :call-seq: # ostruct[name] -> object # - # Returns the value of an attribute, or `nil` if there is no such attribute. + # Returns the value of an attribute, or +nil+ if there is no such attribute. # # require "ostruct" # person = OpenStruct.new("name" => "John Smith", "age" => 70) # person[:age] # => 70, same as person.age # @@ -450,11 +450,16 @@ end end update_to_values!(h) end - # Make all public methods (builtin or our own) accessible with `!`: - instance_methods.each do |method| + # Make all public methods (builtin or our own) accessible with <code>!</code>: + give_access = instance_methods + # See https://github.com/ruby/ostruct/issues/30 + give_access -= %i[instance_exec instance_eval eval] if RUBY_ENGINE == 'jruby' + give_access.each do |method| + next if method.match(/\W$/) + new_name = "#{method}!" alias_method new_name, method end # Other builtin private methods we use: alias_method :raise!, :raise