Created
February 13, 2012 13:12
-
-
Save nthj/1816922 to your computer and use it in GitHub Desktop.
Other
This file contains hidden or 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 Estimated < Other; end | |
class Forwarded < Other; end | |
case discussable | |
when Estimated then :queued # discussable.estimate? | |
when Forwarded then :read # discussable.forward? | |
else :unread | |
end |
This file contains hidden or 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
# Create by passing the method you want to call | |
# ESTIMATED = Other.new(:estimate?) | |
# | |
# Guesses by class name if no flag passed: | |
# class Estimated < Other; end | |
class Other < Struct.new(:flag) | |
class << self | |
def === other | |
# try estimated? estimate? estimat?, forwarded? forwarde? forward? | |
other.send (0..2).map { |o| name.demodulize.downcase[0..(-o)].questionable } | |
end | |
end | |
def === other | |
other.try flag | |
end | |
end |
This file contains hidden or 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
# String extensions | |
class String | |
def questionable | |
questionable? ? to_s : "#{to_s}?" | |
end | |
def questionable! | |
replace questionable | |
end | |
def questionable? | |
self[-1, 1] == '?' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment