This file contains hidden or 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 << Object | |
def my_aa(sym) | |
define_method(sym) do | |
instance_variable_get("@#{sym}") | |
end | |
define_method("#{sym}=") do |v| | |
instance_variable_set("@#{sym}", v) | |
end | |
end |
This file contains hidden or 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 method_missing(name, *args) | |
match = /get_(.*)/.match(name.to_s) | |
if match and match[1] | |
puts match[1] | |
self.class_eval do | |
define_method(name) do | |
return self[match[1]] | |
end | |
end |
This file contains hidden or 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
# Replace Inheritance with Delegation | |
# http://refactoring.com/catalog/replaceInheritanceWithDelegation.html | |
# class Roster < Array | |
# attr_accessor :title | |
# def to_s | |
# out = "#{title}\n" | |
# each do |item| | |
# out += "#{item}\n" |
This file contains hidden or 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
File.new('/tmp/http-log', 'w') do |f| | |
http = Net::HTTP.new | |
http.set_debug_output(f) | |
http.start { .... } | |
end |
This file contains hidden or 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
$ java -cp clojure.jar clojure.main ~/Projects/Clojure/fake-cs.clj | |
Sending... | |
#<Agent@1f758500: {:name Music, :online false}> | |
Starting... | |
Exception in thread "main" java.lang.NullPointerException (fake-cs.clj:0) | |
at clojure.lang.Compiler.eval(Compiler.java:5440) | |
at clojure.lang.Compiler.load(Compiler.java:5857) | |
at clojure.lang.Compiler.loadFile(Compiler.java:5820) | |
at clojure.main$load_script.invoke(main.clj:221) |
This file contains hidden or 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
describe "should respond_to" do | |
it "works the same as respond_to?" do | |
group = RSpec::Core::ExampleGroup.describe {} | |
a = group.new | |
a.respond_to?(:be).should be_true | |
a.should respond_to(:be) | |
end | |
end |
This file contains hidden or 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
;; Note that the equal test got closed too early... | |
(deftest bad-test | |
(is (= {:a 1}) | |
{:a 1})) | |
;; Has the error: | |
;; error in process filter: Wrong number of arguments: nil, 6 |
This file contains hidden or 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 | |
attr_accessor :a | |
def initialize | |
@a = 1 | |
end | |
end | |
foo = Foo.new | |
puts foo.a |
This file contains hidden or 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 PrivacyFilter | |
class << self | |
def filter(controller) | |
@controller = controller | |
first_article? or administrator? or user? | |
end | |
def first_article? | |
@controller.params[:id] == 1 |
This file contains hidden or 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 | |
def self.new(arg1, arg2) | |
B.new(arg2, arg1) | |
end | |
end | |
class B | |
def initialize(alpha, beta) | |
puts "#{alpha}, #{beta}" | |
end |
OlderNewer