-
-
Save a-bash/3154460 to your computer and use it in GitHub Desktop.
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 Fixnum | |
def seconds | |
self | |
end | |
def minutes | |
self * 60 | |
end | |
def hours | |
minutes * 60 | |
end | |
def days | |
hours * 24 | |
end | |
def ago | |
Time.now - self | |
end | |
def from_now | |
Time.now + self | |
end | |
end | |
puts Time.now # => Thu Dec 23 09:41:04 +0100 2010 | |
puts 3.days.from_now # => Sun Dec 26 09:41:06 +0100 2010 |
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 Condition < Proc | |
def ===(object) | |
call(object) | |
end | |
end | |
even = Condition.new { |x| x % 2 == 0 } | |
odd = Condition.new { |x| x % 2 != 0 } | |
case 3 | |
when even | |
puts "Even!" | |
when odd | |
puts "Odd!" | |
end |
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
require 'rubygems' | |
require 'builder' | |
builder = Builder::XmlMarkup.new | |
builder.person do |b| | |
b.name("Jim") | |
b.phone("555-1234") | |
end | |
# Prints: | |
# <person> | |
# <name>Jim</name> | |
# <phone>555-1234</phone> | |
# </person> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment