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 << self | |
def with(expression) | |
yield expression | |
end | |
end | |
# ----------------------------------------------------- | |
def really_long_and_very_complicated_expression | |
'quite long text ' * 400 |
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 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
class String | |
def strip_tags | |
self.gsub(/<[^<>]+>/,'') | |
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
module X | |
def x | |
"x" | |
end | |
module_function :x | |
def self.included(base) | |
base.class_eval do | |
public :x | |
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 Fixnum | |
%w(x y).each do |m| | |
define_method "norm_#{m}" do | |
(self + 3 * Urf.__send__("max_#{m}")) % Urf.__send__("max_#{m}") | |
end | |
end | |
end | |
Urf = Class.new{ | |
attr_reader :feeld |
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.new do | |
def initialize | |
puts "oh, ein neuer BH!" | |
end | |
end | |
∆_∆.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 Object | |
# nil if false, else self | |
def only_if(&block) | |
self if self.instance_eval(&block) | |
end | |
end | |
puts ''.only_if { length > 0 } || 'previously blank' | |
# => 'previously blank' |
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
#--------------------------------------------------- | |
# pretty fast | |
1 2 3 4 5 6 7 8 9 1 | |
x x x x x x | |
. o o . . | |
o o o o | |
#--------------------------------------------------- | |
# pretty fast | |
1 2 3 4 5 6 7 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 << (Logger = []) | |
def to_s | |
join("\n") | |
end | |
def <=(s) | |
self << line << s << line | |
end | |
def line(n = 50) |
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
ruby -e "require 'base64'; puts Base64.decode64(ARGV[0])" <somebase64string> |
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 -(h) | |
reject do |k, v| | |
h.has_key?(k) && (v == h[k]) | |
end | |
end | |
end | |
describe Hash, 'difference between two hashes' do | |
it "should return a hash" do |
OlderNewer