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
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 |
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
[...].forty_two # Retourne le 42éme élément du tableau |
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
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 |
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
var a = true | |
typeof a | |
=> "boolean" | |
a.constructor.name | |
=> "Boolean" | |
typeof Boolean | |
=> "function" | |
Boolean.constructor.name | |
=> "Function" |
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
function A() { | |
// private | |
var _foo = "foo"; | |
function foo() { | |
return _foo; | |
}; | |
// public | |
this._bar = "bar"; |
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
var com = {}; | |
com.synbioz = {}; | |
com.synbioz.app = function(name, url) { | |
this._name = name; | |
this._url = url; | |
} | |
new com.synbioz.app("foo", "foo.com") |
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
function Human() { this.speak = function() { return "bonjour" } } | |
function Monster() { this.speak = function() { return "grrrr" } } | |
function Hulk() {} | |
// hulk inherits from Human | |
Hulk.prototype = new Human() | |
hulk1 = new Hulk() | |
hulk1.speak() | |
=> "bonjour" |
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
// still does'nt work | |
hulk1.prototype = new Monster(); | |
hulk1.speak() | |
=> "bonjour" |
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
hulk1.__proto__ = new Monster | |
hulk1.speak() | |
=> "grrrr" |
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 Animal | |
attr_accessor :name, :age, :weight | |
def initialize(name, weight, age) | |
@name = name | |
@weight = weight | |
@age = age | |
end | |
def to_s |
OlderNewer