Skip to content

Instantly share code, notes, and snippets.

# *&^)^(&(&&*^)^(* encoding: utf-8 *)*)&)^)^%*%&*%**
ÜglÈÊCÕnsªnt = "HAIUGLYCODEZ"
alias :send ∴; alias :get ∵
%w|rubygems sinatra|.each{|_|require _}
%w|gem load|.each{|_| ∴ _, 'kitty'}
(℧=Kitty).∴ *%w(define_method print) do |*⇧| ⇧.∴:join end
∵ %r{\/} do content_type "nialp/txet".reverse and ℧.new.random_kitty end
# gem install kitty
# ruby kitty_server.rb &
# curl http://localhost:4567
require 'benchmark'
class Chad
def a_method
1
end
end
c = Chad.new
Benchmark.bmbm do |bm|
bm.report("send") {100000.times{ c.send(:a_method)}}
require 'test/unit'
class Strange<Test::Unit::TestCase
def test_x
assert_raises NameError do
strange
end
begin
strange = THIS_CONSTANT_IS_MISSING
rescue NameError # we expect this
end
require 'spec'
class Person
def awesome?
true
end
end
describe Person do
it "should return all people" do
Person.should_receive(:all).and_return []
module Vocal
def speak
puts "#{self} says hello"
end
end
class Object
def ekstend(mod)
class << self
self
class LoggerClass
def self.attr_logger(attribute_name)
iv_name = "@#{attribute_name}"
define_method(attribute_name) do
instance_variable_get(iv_name)
end
define_method("#{attribute_name}=") do |value|
STDERR.puts "setting #{attribute_name} to #{value}"
instance_variable_set(iv_name, value)
end
class LoggerClass
def self.attr_logger(attribute_name)
class_eval "def #{attribute_name}; @#{attribute_name}; end"
class_eval "def #{attribute_name}=(val); @#{attribute_name} = val; end"
end
end
class Person < LoggerClass
attr_logger :age
attr_logger :name
module Names
# TODO
end
Object.send(:include, Names)
class Person
displayed_attribute :name
displayed_attribute :age
displayed_attribute :ssn, :label => "Social Security Number"
#https://gist.github.com/786350
module Names
def self.included(klass)
klass.extend ClassLevelMethods
klass.send(:attr_reader, :displayed_attribute_info)
end
def to_s
"<#{self.class.name} " +
self.class.displayed_attribute_info.map do |attr_name, label|
# use .each (or each_with_index) and iteration to implement these
array_of_numbers = [1,2,3,4,5]
number_to_add = 2
puts array_of_numbers.add_a_number_to_each_of_these_numbers(number_to_add)
# => [3, 4, 5, 6, 7]
list = [:name, 'Chad', :place, 'Virginia']
list.turn_into_hash