Skip to content

Instantly share code, notes, and snippets.

function F() {
var arr = [], i;
for (i = 0; i < 3; i++) {
arr[i] = (function (x) {
return function () {
return x; };
}(i)); }
return arr; }
This gives you the expected result:
> var arr = F(); > arr[0]();
$ rake -T spec
rake spec # Run all specs in spec directory (excluding plugin specs)
rake spec:controllers # Run the code examples in spec/controllers
rake spec:helpers # Run the code examples in spec/helpers
rake spec:models # Run the code examples in spec/models
>
$ rake spec:models
rake aborted!
Don't know how to build task 'spec:models'
2.0.0p247 :027 > Time.parse("5/6", Time.now)
=> 2014-05-06 00:00:00 -0700
2.0.0p247 :029 > Time.parse("5/6/2014")
=> 2014-06-05 00:00:00 -0700
2.0.0p247 :030 > Time.parse("2014/5/6")
=> 2014-05-06 00:00:00 -0700
describe "#years" do
it "should return a list of years" do
Time.stub(:now).and_return Time.parse("2005-01-01")
Membership.years.should == [["04-05",2004], ["05-06",2005], ["06-07",2006], ["07-08",2007]]
Time.stub(:now).and_return Time.parse("2007-01-01")
Membership.years.should == [["06-07",2006], ["07-08",2007], ["08-09",2008], ["09-10",2009]]
end
end
mysql> DESCRIBE grades;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | NULL | |
| position | int(11) | NO | | 0 | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
# fax.extension= looks nicer than fax.qualifier
def extension=(ext)
write_attribute(:qualifier, ext)
end
# fax.extension looks nicer than fax.qualifier
def extension
read_attribute(:qualifier)
end
def test
name = 'jim'
puts "hi"
puts yield
puts "hi"
end
name = 'bob'
test do
map.resources :products, :collection => { :notify => :post } do |products|
products.resources :orders,
:member => {
:change_payment => :get,
:invoice => :get,
:pricing => :get
},
:collection => {
:pre => :any,
:new => :post
map.with_options :controller => "events" do |event|
event.connect "/events/index.html", :action => "index"
event.connect "/events/past_events", :action => "past_events"
event.connect "/events/past_events/:year", :action => "past_events"
event.connect "/events/past_events/:year/:id", :action => "show"
end
# Handles all public requests for authors - like the list and show pages
class AuthorsController < ApplicationController
# Handle all other actions that are given from named routes gracefully
# by redirecting to the page not found page
%w{new create edit update destroy}.each do |name|
define_method name do
ap "-------1"