Skip to content

Instantly share code, notes, and snippets.

@a-bash
Forked from josevalim/1_open.rb
Created July 21, 2012 03:32
Show Gist options
  • Save a-bash/3154460 to your computer and use it in GitHub Desktop.
Save a-bash/3154460 to your computer and use it in GitHub Desktop.
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
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
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