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
[14:42:11 projects]$ ruby my_o.rb | |
70255884061920: hello |
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.9.1 :001 > Video.where(video_id: 1234).first_or_initialize.video_id | |
Video Load (2.0ms) SELECT `videos`.* FROM `videos` WHERE `videos`.`video_id` = '1234' LIMIT 1 | |
=> "'1234'" |
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 'rubygems' | |
require 'benchmark/ips' | |
class ExampleClass | |
def foo; 42; end | |
end | |
non_dci_object = ExampleClass.new | |
module ExampleMixin |
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
pete@balloon:~/projects/rspec-expectations$ rspec rspec_test.rb | |
FF | |
Failures: | |
1) Hash #=~ displays confusing error message when hashes are equal | |
Failure/Error: actual.should =~ actual | |
expected: {:foo=>"bar"} | |
got: {:foo=>"bar"} (using =~) | |
Diff:{:foo=>"bar"}.==({:foo=>"bar"}) returned false even though the diff between {:foo=>"bar"} and {:foo=>"bar"} is empty. Check the implementation of {:foo=>"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
Organization.where("name != 'national'") | |
email = "foo@bar.com" | |
User.where(email: email).destroy_all | |
def sql_queries(title, verbose=false) | |
queries = Hash.new(0) | |
callback = lambda {|*args| | |
sql = args.last[:sql] |
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
One that seems to surprise a lot of people is Hash.from_xml: | |
> hash = {:foo => 'bar', :baz => 'qux'} | |
=> {:foo=>"bar", :baz=>"qux"} | |
> hash.to_xml | |
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n | |
<foo>bar</foo>\n <baz>qux</baz>\n</hash>\n" | |
> Hash.from_xml(hash.to_xml) | |
=> {"hash"=>{"foo"=>"bar", "baz"=>"qux"}} |
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 'ostruct' | |
module Awesome | |
def self.config | |
@config | |
end | |
def self.configure | |
yield(config) | |
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
module Awesome | |
@config = {} | |
def self.configure | |
yield(self) | |
end | |
def self.method_missing method, *args, &block | |
if method.to_s[-1] == '=' | |
@config[method[0..-2].to_sym] = args.first |
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 'rubygems' | |
require 'sexp_processor' | |
#def uses_if | |
# if some_func | |
# if some_other_func | |
# return | |
# end | |
# 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
pete@balloon ~/projects/heckle $ rake | |
/home/pete/.rvm/rubies/ruby-1.8.7-p358/bin/ruby -w -I../../ParseTree/dev/lib:../../ParseTree/dev/test:../../RubyInline/dev/lib:../../ruby2ruby/1.3.1/lib:../../ZenTest/dev/lib:../../sexp_processor/dev/lib:lib:lib:bin:test:. -e 'require "rubygems"; require "test/unit"; require "test/test_heckle.rb"' -- | |
Loaded suite -e | |
Started | |
...............EE........F..F.............. | |
Finished in 14.142885 seconds. | |
1) Error: | |
test_default_structure(TestHeckleClassMethod): | |
NoMethodError: undefined method `first' for nil:NilClass |