Instantly share code, notes, and snippets.

View class_instance_variables_and_inheritance.rb
module Echoer
def echoes(*phrases)
@known_phrases.concat(phrases)
@known_phrases.each do |phrase|
next if self.respond_to?(phrase.to_sym)
define_method("#{phrase}") { phrase.to_s }
end
end
View modules.rb
module Motion
def default_movement
"walking"
end
end
module Flight
extend Motion
def movement
View string_lookup_case.rb
module StringLookup
def self.lookup(string)
case string
when /^Foo.*$/ then 'group A'
when /^F.*$/ then 'group B'
when /^Bar.*$/ then 'group C'
when /^Baz.*$/ then string.gsub('a', '0')
end
end
View server.rb
require 'sinatra/base'
class GetServer < Sinatra::Base
set :logging, nil
get '/' do
puts "count: #{params["request_number"]}"
end
end