Skip to content

Instantly share code, notes, and snippets.

var a = true
typeof a
=> "boolean"
a.constructor.name
=> "Boolean"
typeof Boolean
=> "function"
Boolean.constructor.name
=> "Function"
var a1 = ["4", "2"]
Array.prototype.size = function() { return this.length; }
var a2 = ["s", "y", "n", "b", "i", "o", "z"]
a1.size()
=> 2
a2.size()
=> 7
[...].forty_two # Retourne le 42éme élément du tableau
def colors(size)
1.upto(size).inject([]) { |colors, index|
r, g, b = yield
colors << "#%02x%02x%02x" % [r, g, b]
}
end
def hsv_to_rgb(h, s, v)
h_i = (h * 6).to_i
f = h * 6 - h_i