Created
May 23, 2011 19:05
-
-
Save danreedy/987305 to your computer and use it in GitHub Desktop.
Example Method_Missing code for an approval model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Approval | |
attr_accessor :status | |
def method_missing(meth, *args, &blk) | |
method_name = meth.to_s | |
if method_name =~ /\?$/ | |
self.status.downcase.eql? method_name.gsub(/\?$/,'') | |
else | |
super | |
end | |
end | |
end | |
a = Approval.new | |
a.status = "Pending" | |
puts a.pending? | |
puts a.approved? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment