Skip to content

Instantly share code, notes, and snippets.

@jmonegro
Forked from jamonholmgren/NSObject.rb
Created April 27, 2013 23:02
Show Gist options
  • Save jmonegro/5475093 to your computer and use it in GitHub Desktop.
Save jmonegro/5475093 to your computer and use it in GitHub Desktop.
class NSObject
def method_missing(meth, *args)
obj_c_meth = meth.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
if respond_to?(obj_c_meth)
send obj_c_meth, *args
else
raise NoMethodError.new(meth.to_s)
end
end
end
# In the REPL:
v = UIView.new
# => #<UIView:0xaa45260>
v.background_color = UIColor.white_color
# => #<UICachedDeviceWhiteColor:0xaa41180>
v.backgroundColor
# => <UICachedDeviceWhiteColor:0x967c2e0>
v.asdf
# => #<NoMethodError: asdf>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment