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 Person | |
attr_accessor :first_name, :last_name | |
def whole_name | |
first_name + " " + last_name | |
end | |
end | |
p = Person.new | |
p.first_name = "David" |
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 A # top-level A | |
end | |
module M | |
module ClassMethods | |
def create_an_a | |
A.new # top-level A | |
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
# Forked from trevoke | |
require 'csv' | |
require 'yaml' | |
require 'rails/all' | |
require 'active_record' | |
require 'active_support' | |
require 'sqlite3' |
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
This is from the end of weakref.rb: | |
if __FILE__ == $0 | |
# require 'thread' | |
foo = Object.new | |
p foo.to_s # original's class | |
foo = WeakRef.new(foo) | |
p foo.to_s # should be same class | |
ObjectSpace.garbage_collect | |
ObjectSpace.garbage_collect |
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
I'm puzzled by the behavior of take_while and drop_while when called without | |
a block. They return enumerators -- that part I understand -- but I'm not | |
understanding how those enumerators behave. | |
Here's what I mean: | |
>> enum = [1,2,3,4,5].take_while | |
=> #<Enumerator: [1, 2, 3, 4, 5]:take_while> | |
>> enum.next | |
=> 1 |
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
Update: I figured it out. I was loading the .js file twice. | |
In the view: | |
<%= link_to "Toggle comment", "#", :id => "toggle-comment" %> | |
<p id="comment" style="display:none;">Comment: <%= @scratchpad.comment %></p> |
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 max_length_histogram(str) | |
Hash.new(0).tap do |hist| | |
str.scan(/((.)\2*)/) do |substring, letter| | |
hist[letter] = [ hist[letter], substring.size ].max | |
end | |
end | |
end | |
def longest_run(str) | |
max_length_histogram(str).max_by {|letter, n| n } |
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
ree-1.8.7-2010.02 :001 > res = Team.search { keywords "Mets" } | |
=> <Sunspot::Search:{:defType=>"dismax", :q=>"Mets", :rows=>30, :start=>0, | |
:fl=>"* score", :qf=>"name_text", :fq=>["type:Team"]}> | |
ree-1.8.7-2010.02 :002 > res.results | |
=> [#<Team _id: BSON::ObjectId('4dfa2262508c319700000001'), name: "Mets">] | |
ree-1.8.7-2010.02 :003 > Team.reindex(:batch_size => false) | |
=> {"responseHeader"=>{"QTime"=>137, "status"=>0}} | |
ree-1.8.7-2010.02 :004 > res = Team.search { keywords "Mets" } | |
=> <Sunspot::Search:{:defType=>"dismax", :q=>"Mets", :rows=>30, :start=>0, | |
:fl=>"* score", :qf=>"name_text", :fq=>["type:Team"]}> |
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
Why does the app always take the HTML/index.html.erb path when the link is clicked? | |
Does index.js.erb not work any more? | |
# in controller | |
def index | |
@page = Page.find(params[:page_id]) | |
@ideas = @page.ideas | |
respond_to do |format| | |
format.js | |
format.html |
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
1. Without the change to line 7 of scripts/rvm: | |
$ rvm default | |
$ ruby -v | |
ruby 1.9.2p0 (2010-08-18 revision 29036) [i386-darwin9.8.0] | |
$ sh | |
sh: /Users/dblack/.rvm/scripts/rvm: line 7: syntax error near unexpected token | |
`<' | |
sh: /Users/dblack/.rvm/scripts/rvm: line 7: `\grep -q '^rvm ()' < <( declare -f | |
) # Is RVM is a shell function?' |
NewerOlder