Skip to content

Instantly share code, notes, and snippets.

@JonathonMA
Created October 24, 2013 03:09
Show Gist options
  • Save JonathonMA/7130682 to your computer and use it in GitHub Desktop.
Save JonathonMA/7130682 to your computer and use it in GitHub Desktop.
Why wait for ruby 2.1?
gem 'minitest', '>= 5'
require 'minitest/autorun'
module Kernel
def private_def method_name, &block
define_method method_name, &block
private method_name
end
end
class PrivateDefTest < MiniTest::Test
class Foo
private_def :foo do
:foo
end
end
def test_Foo_foo_exists
assert_equal :foo, Foo.new.send(:foo)
end
def test_Foo_foo_is_private
assert_raises NoMethodError do
Foo.new.foo
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment