Skip to content

Instantly share code, notes, and snippets.

@genya0407
Created October 14, 2019 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genya0407/eef9a326aca65ddb331d86b43f4a3cab to your computer and use it in GitHub Desktop.
Save genya0407/eef9a326aca65ddb331d86b43f4a3cab to your computer and use it in GitHub Desktop.
class Hoge
def define_new_method
def this_is_defined_inside_method
puts "fuga"
end
end
end
begin
h1 = Hoge.new
h1.this_is_defined_inside_method # メソッドは定義されていないためエラー
rescue NoMethodError => e
puts e
end
h2 = Hoge.new
h2.define_new_method
h2.this_is_defined_inside_method # これは動く
h3 = Hoge.new
h3.this_is_defined_inside_method # 動く ← !?!?!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment