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
[0..9, ?a..?z, ?A..?Z].map(&:to_a).flatten.sample(10).join #size has been hard coded as 10 here |
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
# Coding hazard. | |
class CoOrdinate | |
attr_reader :x, :y | |
def initialize(x, y) | |
@x = x | |
@y = y | |
end | |
end |
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
# Execute this file as follows and compare the results in ruby 1.8.*: | |
# | |
# ruby class_var_ex.rb | |
# ruby class_var_ex.rb "include module" | |
# ruby class_var_ex.rb "include module" "include global" | |
# ruby "include global" | |
@@test = 9 if ARGV.last == "include global" | |
module X |
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
Number.prototype.times = function(str) { | |
var result = "", i = this; | |
while(i-- > 0) {result += str;} | |
return result; | |
}; |
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
// Exercise 2 - Closures | |
// Wrap the following code in a closure and export only the "countdown" function. | |
// Code | |
var countdown = function() { | |
var index; | |
function log(){ |
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 logCar(obj) { | |
console.log("I'm a " + obj.color + " " + obj.make); | |
} | |
var Car = function(make, color){ | |
this.make = make; | |
this.color = color; | |
}; | |
Car.prototype = (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.prototype.cache = (function() {return {};})(); | |
Function.prototype.setCache = (function() { | |
var self = this; | |
return function(key) { | |
if(!this.cache[key]) | |
this.cache[key] = this.call(self, key); | |
}; | |
})(); |
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 Person = function(name) { | |
this.name = name; | |
}; | |
Person.prototype.getName = function() { | |
return this.name; | |
}; | |
var thomas = new Person('Thomas'); | |
var amy = new Person('Amy'); |
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 Outer | |
class Inner | |
def initialize(attrs) | |
@obj = attrs | |
end | |
def do_something | |
# do somehting with the @obj | |
@obj | |
end |
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
require 'rspec' | |
RSpec.configure do |config| | |
config.mock_with :rspec | |
config.color_enabled = true | |
end | |
module MyHashTools | |
def get_val_for(sym) |
OlderNewer