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 Lib | |
def has_color | |
define_method(:color) do 'red' end | |
end | |
end | |
class Car | |
extend Lib | |
has_color | |
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 String | |
def segments | |
segments = split(/\./) | |
while segments.size > 1 | |
yield(segments.join('.')) | |
segments.pop | |
end | |
yield('.') | |
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
#!/usr/bin/env ruby | |
# hackery to simulate a file | |
require 'stringio' | |
RealFile = File | |
Object.send(:remove_const, :File) | |
File = StringIO | |
def StringIO.open(data); x=new(data);x.rewind; x; end | |
# end of hackery | |
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 String | |
def reindent(to, tabwidth=nil) | |
indenter = (tabwidth ? " "*tabwidth : "\t")*to | |
initial = self[/\A[\t ]*/] | |
gsub(/^(?:#{initial})?/, indenter) | |
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
$ ruby cgi.rb | |
(offline mode: enter name=value pairs on standard input) | |
sprache=java | |
Content-Type: text/html | |
Content-Length: 14 | |
code ist java | |
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
/* | |
$Id: strscan.c 11708 2007-02-12 23:01:19Z shyouhei $ | |
Copyright (c) 1999-2006 Minero Aoki | |
This program is free software. | |
You can distribute/modify this program under the terms of | |
the Ruby License. For details, see the file COPYING. | |
*/ | |
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
# include time matters | |
module CallInspectable | |
def self.included(by) | |
inherited_methods = by.public_instance_methods-by.public_instance_methods(false) | |
inherited_methods.sort.each { |name| | |
class_eval("def #{name}(*args); $stderr.puts \"Called '#{name}' in #{by}\"; super; end") | |
} | |
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 CallInspectable | |
def intercept_all_calls(&block) | |
all_methods = superclass.public_instance_methods | |
m = Module.new do | |
all_methods.each { |method_name| | |
define_method(method_name) do |*args| | |
block.call(method_name) | |
super | |
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
SELECT cv.* FROM candidate_versions AS cv JOIN ( | |
SELECT lower_bound.candidate_id, MIN(lower_bound.updated_at) AS lower_updated_at, MAX(upper_bound.updated_at) AS upper_updated_at FROM ( | |
SELECT MAX(updated_at) as updated_at, candidate_id FROM candidate_versions WHERE updated_at <= '2009-01-01' GROUP BY candidate_id | |
UNION ALL | |
SELECT MIN(updated_at) as updated_at, candidate_id FROM candidate_versions WHERE updated_at BETWEEN '2009-01-01' AND '2010-01-01' GROUP BY candidate_id | |
) AS lower_bound JOIN ( | |
SELECT MAX(updated_at) as updated_at, candidate_id FROM candidate_versions WHERE updated_at <= '2010-01-01' GROUP BY candidate_id | |
) AS upper_bound ON lower_bound.candidate_id=upper_bound.candidate_id | |
WHERE lower_bound.candidate_id < 10020 | |
GROUP BY lower_bound.candidate_id |
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
#!/usr/bin/env ruby | |
require 'optparse' | |
utf8 = true | |
colors = false | |
opts = OptionParser.new("", 24, ' ') do |opts| | |
opts.banner = "Usage: #{$PROGRAM_NAME} [options] [directory]" |
OlderNewer