Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias less methods #34

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/ostruct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,12 @@ def init_with(coder) # :nodoc:
end

# Make all public methods (builtin or our own) accessible with <code>!</code>:
instance_methods.each do |method|
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
Expand Down
1 change: 1 addition & 0 deletions test/ostruct/test_ostruct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def test_access_original_methods
os = OpenStruct.new(method: :foo, hash: 42)
assert_equal(os.object_id, os.method!(:object_id).call)
assert_not_equal(42, os.hash!)
refute os.methods.include?(:"!~!")
end

def test_override_subclass
Expand Down