Skip to content

@ngollan /test.rb secret

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
$ rvm use 1.9.3
Using /home/ngollan/.rvm/gems/ruby-1.9.3-p194
Running /home/ngollan/.rvm/hooks/after_use
$ ruby test2.rb
#initialize: private -> private
#i_am_public: public -> public
#i_am_private: private -> private
$ rvm use rbx
Using /home/ngollan/.rvm/gems/rbx-head
Running /home/ngollan/.rvm/hooks/after_use
$ RBXOPT="-X19" ruby test2.rb
#initialize: private -> public
#i_am_public: public -> public
#i_am_private: private -> private
module Publicize
def self.included(base)
%w(initialize i_am_public i_am_private).each do |m|
STDOUT.write "##{m}: #{base.instance_methods.map(&:to_s).include?(m) ? 'public' : ''}#{base.private_instance_methods.map(&:to_s).include?(m) ? 'private' : ''} -> "
base.send :alias_method, "old_#{m}", m
base.send :alias_method, m, "outer_#{m}"
puts "#{base.instance_methods.map(&:to_s).include?(m) ? 'public' : ''}#{base.private_instance_methods.map(&:to_s).include?(m) ? 'private' : ''}"
end
end
def outer_initialize(*args)
old_initialize(*args)
end
def outer_i_am_public
end
private
def outer_i_am_private
end
end
class ThatSimple
def i_am_public
end
private
def i_am_private
end
public
include Publicize
end
# Should be about minimal.
#
# MRI 1.8.7: true, false
# MRI 1.9.3: true, true
# rbx (both 1.9 and 1.8 mode): true, false
class Hello
private
def initialize
end
public
def foo
end
p private_instance_methods.map(&:to_s).include?('initialize')
alias_method :initialize, :foo
p private_instance_methods.map(&:to_s).include?('initialize')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.