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 | |
B = Module.new | |
def ieval(&block) | |
instance_eval(&block) | |
end | |
end | |
B = Module.new |
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 CSVParser | |
def initialize(line_handler=nil) | |
@line_handler = line_handler | |
@current_line = [] | |
@lines = [] | |
end | |
def receive(chunk) | |
#handle the chunk depending on state | |
#if we detect end of line: |
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 PrivacyExample | |
def some_public_method | |
self.some_private_method | |
end | |
def some_private_method | |
"o hai" | |
end | |
private :some_private_method | |
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 MasterOfCeremonies { //I hate naming in potted examples | |
public void handle(Dog dog) { | |
dog.speak(); | |
} | |
} | |
class Dog { | |
public void speak() { | |
//something | |
} |
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 Doer { | |
public void doStuff(Speaker speaker) { | |
speaker.speak(); | |
} | |
} | |
interface Speaker { | |
void speak(); | |
} |
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
>> User.last.update_attributes(nil) | |
=> true |
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
require 'benchmark' | |
class PerfTest | |
def with_inject(array) | |
mapped_vals.inject(array, :<<) | |
end | |
def with_plus(array) | |
array + mapped_vals | |
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
public List<Foo> sort(List<Foo> foos) { | |
return Collections.sort(foos, new Comparator<Foo>() { | |
@Override | |
public int compare(Foo a, Foo b) { | |
//comparison logic | |
} | |
}); | |
} |
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
(function() { | |
var C = JS.Console; | |
var adapterConditions = {}; | |
var registerAdapterCondition = function(check, initializer) { | |
adapterConditions[check] = initializer; | |
}; | |
var configureC = function() { | |
C.adapter = new C.Base(); |
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
for file in $(find . -name '*.rb') | |
do | |
if [ $(egrep "\b[A-Z]" $file | wc -l) -gt $(egrep "(class|module)" $file | wc -l) ] | |
then | |
echo $file " fails" | |
fi | |
done | wc -l |