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 'syntax/convertors/html' | |
def to_html(dirname) | |
convertor = Syntax::Convertors::HTML.for_syntax "ruby" | |
Dir.chdir(dirname) | |
Dir.glob("*.rb") do |filename| | |
f = File.new(filename.gsub(".rb", ".html"), "w") | |
f << convertor.convert( File.read( filename ) ) | |
f.close |
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 'date' | |
s = '2998-12-31' | |
date = Date.parse(s) | |
f = date.strftime('%d-%b-%G') | |
puts f #=> 31-Dec-2999 ... Why? |
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
# Uses Ruby 1.9 syntax for lambdas | |
counter = -> initial do | |
val = initial | |
foo = {next: -> {val += 1}, reset: -> {val = initial}} | |
def foo.method_missing(meth, *args) | |
self[meth].call | |
end | |
foo | |
end | |
c = counter.(10) |
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 Foo | |
def self.bar | |
'heynow' | |
end | |
end | |
# is equivalent to | |
module Foo | |
def 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
module Foo | |
module_function | |
def bar | |
'heynow' | |
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
module Foo | |
module_function | |
def foo | |
'hey' | |
end | |
def bar | |
'now' | |
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 Something | |
include Foo | |
def heynow | |
'foo' + bar + baz | |
end | |
end | |
puts Something.new.foo # "hey" | |
puts Something.new.bar # "now" |
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
/\b((?![\w]*Foo)\w+)\b/ |
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
public interface Foo { | |
Bar makeABar(String hey, List now) throws BarClosedException; | |
} |
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
public class StubFoo implements Foo { | |
public boolean makeABarCalled; | |
public String makeABarHey; | |
public List makeABarNow; | |
public Bar makeABarReturn; | |
public BarClosedException makeABarException; | |
public Bar makeABar(String hey, List now) { | |
makeABarCalled = true; | |
makeABarHey = hey; | |
makeABarNow = now; |
OlderNewer