Skip to content

Instantly share code, notes, and snippets.

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
require 'date'
s = '2998-12-31'
date = Date.parse(s)
f = date.strftime('%d-%b-%G')
puts f #=> 31-Dec-2999 ... Why?
# 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)
module Foo
def self.bar
'heynow'
end
end
# is equivalent to
module Foo
def bar
module Foo
module_function
def bar
'heynow'
end
end
module Foo
module_function
def foo
'hey'
end
def bar
'now'
end
class Something
include Foo
def heynow
'foo' + bar + baz
end
end
puts Something.new.foo # "hey"
puts Something.new.bar # "now"
/\b((?![\w]*Foo)\w+)\b/
public interface Foo {
Bar makeABar(String hey, List now) throws BarClosedException;
}
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;