Skip to content

Instantly share code, notes, and snippets.

@bayleedev
Created April 16, 2013 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bayleedev/5399170 to your computer and use it in GitHub Desktop.
Save bayleedev/5399170 to your computer and use it in GitHub Desktop.
class Foo
private
def self.bar
puts 'I broke your ruby'
end
end
Foo.bar # I broke your ruby
@bayleedev
Copy link
Author

class Foo
  class << self
    protected
    def bar
      puts 'hello'
    end
  end
end

Foo.bar # broken
Foo.instance_eval("class << self; self; end").send(:public, :bar)
Foo.bar

@bayleedev
Copy link
Author

class Foo
  class << self
    def barbaz
      class << self; self; end
    end
    protected
    def bar
      puts 'hello'
    end
  end
end

Foo.barbaz.send(:public, :bar)
Foo.bar

@bayleedev
Copy link
Author

class Foo
  class << self
    protected
    def bar
      puts 'hello'
    end
  end
end

Foo.send(:public_class_method, :bar)
Foo.bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment