Skip to content

Instantly share code, notes, and snippets.

View YaEvan's full-sized avatar
:octocat:
Focusing

EvanYang YaEvan

:octocat:
Focusing
View GitHub Profile
@YaEvan
YaEvan / MethodMissing.rb
Created June 16, 2017 01:56 — forked from Bodacious/MethodMissing.rb
Example of how to rewrite method_missing and respond_to? in Ruby
class CarPart
# does the method name end in _price ?
def ghost_method_condition(name)
!!name.to_s[/_price$/]
end
# rewrite method missing if the method matches ghost_method_condition
def method_missing(name, *args, &block)
super unless ghost_method_condition(name)