Skip to content

Instantly share code, notes, and snippets.

@ksss
Created August 12, 2015 22:06
Show Gist options
  • Save ksss/e2f31e8743540c3009a1 to your computer and use it in GitHub Desktop.
Save ksss/e2f31e8743540c3009a1 to your computer and use it in GitHub Desktop.
File scope method
class OpenClass
module InternalMethods
refine OpenClass do
def foo
:foo
end
end
end
using InternalMethods
def bar
foo
end
end
p OpenClass.new.bar
module InternalMethods
refine Object do
def one
1
end
end
end
using InternalMethods
p one
#! /usr/bin/env ruby
require './lib'
class OpenClass
def baz
foo
end
end
OpenClass.new.baz rescue puts "error: OpenClass#baz cannot call"
one rescue puts "error: `one' cannot call"
# $ ruby main.rb
# :foo
# 1
# error: OpenClass#baz cannot call
# error: `one' cannot call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment