Skip to content

Instantly share code, notes, and snippets.

View wnuqui's full-sized avatar

Wilfrido Nuqui Jr. wnuqui

  • Mandaluyong, Philippines
View GitHub Profile
@wnuqui
wnuqui / gist:2666669
Created May 12, 2012 14:02
What is your quick guess for the 2nd line?
# send following line to irb and see the result
a = 1, b = 2*5
# perhaps this is better
a = 1, (b = 2*5)
@wnuqui
wnuqui / gist:2666644
Created May 12, 2012 13:57
safe conversions instead of to_x
i = "1i"
i.to_i # => 1
Integer(i) # => ArgumentError: invalid value for Integer(): "1i"
f = "1.2f"
f.to_f # => 1.2
Float(f) # => ArgumentError: invalid value for Float(): "1.2f"
@wnuqui
wnuqui / gist:2652404
Created May 10, 2012 10:53
Put your constant at the bottom
class A
def self.constant
[1, 2, 3]
end
B = constant and nil
end
@wnuqui
wnuqui / gist:2651356
Created May 10, 2012 06:16
method chain
class A
def b
data = [1, 2, 3]
def data.foo!
self.sample
end
data
end
end