Skip to content

Instantly share code, notes, and snippets.

class Dog < Animal
end
class Cat < Animal
def to_s
"I'm #{name}, I have #{age} years and I weigh #{weight} (but I have lost some kg)."
end
end
p garfield.class
# Cat
p garfield.class.ancestors
# [Cat, Animal, Object, Kernel]
p garfield.methods.sort
# ["==", "===", "=~", "__id__", "__send__", "age", "age=", "bigger?", "class", "clone", "display", "dup", "enum_for", "eql?", "equal?", "extend", "freeze", "frozen?", "hash", "id", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_variable_defined?", "instance_variable_get", "instance_variable_set", "instance_variables", "is_a?", "kind_of?", "method", "methods", "name", "name=", "nil?", "object_id", "older?", "private_methods", "protected_methods", "public_methods", "respond_to?", "send", "singleton_methods", "taint", "tainted?", "tap", "to_a", "to_enum", "to_s", "type", "untaint", "weight="]
p garfield.methods(false)
# []
# Object.const_get("RUBY_VERSION")
class Cat
STATES = ["hungry", "sated"].freeze
attr_accessor :state
STATES.each do |state|
define_method "#{state}?" do
state == self.state
end
end
p garfield.send :weight
# 10
Cat.send :public, :weight
p garfield.weight
# 10
curl get.pow.cx | sh
ln -s /mon/app ~/.pow/
require File.dirname(__FILE__) + '/config/environment'
run ActionController::Dispatcher.new
touch tmp/restart.txt
group :development do
gem 'guard-pow'
end