Skip to content

Instantly share code, notes, and snippets.

@josevalim
Created December 23, 2010 08:40
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save josevalim/752744 to your computer and use it in GitHub Desktop.
Save josevalim/752744 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>
@brenodamata
Copy link

how does the last one works?
how can you print ou a Builder XML?

cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment