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 f(&b) | |
var_inside_method = :foo | |
binding_of_this_method = binding | |
binding_of_block = b.binding | |
binding_inside_block = b.call | |
eval "p local_variables", binding_of_this_method | |
eval "p local_variables", binding_of_block | |
eval "p local_variables", binding_inside_block |
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 CargoCultGenerator | |
class << self | |
# Creates a useful class name based on the description of it's pupose provided. | |
def class_name(good_descripition_of_purpose, position_of_stars = nil) | |
who_cares = nil if good_descripition_of_purpose | |
dude_serious? if position_of_stars | |
'Base' | |
end | |
# Creates useful files like this one: http://github.com/technoweenie/restful-authentication/tree/master/lib/authorization.rb |
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 MenuBarController | |
def initialize | |
# Create our status bar for the application | |
puts "Initializing....." | |
# menuZone = NSMenu.menuZone() | |
# menu = NSMenu.allocWithZone(menuZone) | |
menuItem = NSStatusBar.systemStatusBar.statusItemWithLength(NSVariableStatusItemLength) | |
# And set it's details |
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
15:01 j`ey: go go go suggestions! | |
15:02 alloy: infinite loo | |
15:02 alloy: p | |
15:02 alloy: what comes out must go in | |
15:02 alloy: crease and irons | |
15:02 j`ey: thats quite an abstract thing :p | |
15:02 alloy: or: irons and crease | |
15:02 j`ey: ooh |
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 'test/unit' | |
# from 'test' to 'mock' is the `it' code, from 'mock' onwards it's mocking. | |
module Test::Unit;T='test';class Failure;def long_display;"#{l=location;Array===l ?l[0]:l}\n#{message}".sub(T,'');end;end;$M={};class TestCase;def self.it(n,&b);define_method(T+n,&b)end;'mock';def m(m,n,v);$M[n]=[m,n,m.method(n),caller[0],v];eval"def m.#{n};m=$M['#{n}'];m[5]=true;m[4];end"end;def teardown;$M.map{|_,m|(class<<m[0];self;end).send(:define_method,m[1],m[2].to_proc);m}.map{|m|$M.delete(m[1]);add_failure("#{m[0].inspect} didn't receive :#{m[1]}",m[3])if !m[5]}end;end;end | |
if $0 == __FILE__ | |
# Test case | |
class TestObject | |
def self.a_class_method | |
false |
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
% script/generate model GrandParent name:string | |
exists app/models/ | |
exists test/unit/ | |
exists test/fixtures/ | |
create app/models/grand_parent.rb | |
create test/unit/grand_parent_test.rb | |
create test/fixtures/grand_parents.yml | |
create db/migrate | |
create db/migrate/20090127182616_create_grand_parents.rb | |
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
/Users/eloy/Documents/DEVELOPMENT/MacRuby/macruby-git-svn/test-macruby/fixtures/IOWaitReadable.c:1:18: error: ruby.h: No such file or directory | |
/Users/eloy/Documents/DEVELOPMENT/MacRuby/macruby-git-svn/test-macruby/fixtures/IOWaitReadable.c:2:21: error: ruby/io.h: No such file or directory | |
/Users/eloy/Documents/DEVELOPMENT/MacRuby/macruby-git-svn/test-macruby/fixtures/IOWaitReadable.c: In function ‘macruby_test_io’: | |
/Users/eloy/Documents/DEVELOPMENT/MacRuby/macruby-git-svn/test-macruby/fixtures/IOWaitReadable.c:8: error: ‘errno’ undeclared (first use in this function) | |
/Users/eloy/Documents/DEVELOPMENT/MacRuby/macruby-git-svn/test-macruby/fixtures/IOWaitReadable.c:8: error: (Each undeclared identifier is reported only once | |
/Users/eloy/Documents/DEVELOPMENT/MacRuby/macruby-git-svn/test-macruby/fixtures/IOWaitReadable.c:8: error: for each function it appears in.) | |
/Users/eloy/Documents/DEVELOPMENT/MacRuby/macruby-git-svn/test-macruby/fixtures/IOWaitReadable.c:8: error: ‘EAGAIN’ undeclared (first use in this |
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 "pp" | |
class Builder | |
def initialize | |
@elements = [] | |
end | |
%w{ html body h1 ul li }.each do |tag| | |
eval %{ | |
def #{tag}(*args) |
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 Foo | |
def self.string_query_accessor(attr, *true_values) | |
true_values.each do |true_value| | |
class_eval %{ | |
def #{true_value}? | |
send(:#{attr}) == '#{true_value}' | |
end | |
}, __FILE__, __LINE__ | |
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
class Hash | |
def diff(other) | |
result = {} | |
union = keys | other.keys | |
result[:not_in_other] = (union - keys).inject({}) { |memo, k| memo[k] = other[k]; memo } | |
result[:not_in_self] = (union - other.keys).inject({}) { |memo, k| memo[k] = self[k]; memo } | |
result[:not_equal] = {} | |
each do |key, value| |
OlderNewer