summaryrefslogtreecommitdiff
path: root/lib/ostruct.rb
diff options
context:
space:
mode:
authorMarc-André Lafortune <github@marc-andre.ca>2021-12-06 23:05:53 -0500
committerMarc-André Lafortune <github@marc-andre.ca>2021-12-06 23:21:07 -0500
commit95d9bcf2b2921baee5dfacdf9dfd606a4c5167a8 (patch)
tree18ea00a86476c9ebf1590e76863a0960b3454e20 /lib/ostruct.rb
parentdfd9728c87640d9699b1e7c63a6fefb6b2797fbc (diff)
[ruby/ostruct] Alias less methods
Skips methods that do not end with letter (in particular `!~` and `=~`) For JRuby, also skip `instance_exec`, `instance_eval` and `eval`
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r--lib/ostruct.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index c2de7a493d..e320e6db41 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -453,7 +453,12 @@ class OpenStruct
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