Skip to content

Instantly share code, notes, and snippets.

View ELLIOTTCABLE's full-sized avatar
🐫

ELLIOTTCABLE

🐫
View GitHub Profile
case my_thing.is_a_flip?
when abc
blah.figgle.babbit
when summat_else
snizzle.bob
when other_thingie
sniff.sniff.sniff
module Enumerable
def inject_with_index(*args, &block)
enum_for(:each_with_index).inject(*args, &block)
end
end
spots = (data = surfline_data.to_hash)[:spot_name].split(',').inject_with_index(Hash.new) {|hash, (name, i)| hash[name] = data[:spot_url].split(',')[i] }
@ELLIOTTCABLE
ELLIOTTCABLE / attr_splat_examples.rb
Created October 10, 2008 00:03
attr_splat's planned functionality
require 'attr_splat'
class Class
class self.singleton
# We don't do this by default, just to be safe. It's perfectly acceptable,
# as attr_*'s API is fully backwards compatible.
#
# Now every example below, attr_splat could safely be replaced with
# attr_accessor
alias_method :attr_accessor, :attr_splat
@ELLIOTTCABLE
ELLIOTTCABLE / attr_splat_examples.rb
Created October 10, 2008 01:26
a fork of a fork!
require 'attr_splat'
class Class
class self.singleton
# We don't do this by default, just to be safe. It's perfectly acceptable,
# as attr_*'s API is fully backwards compatible.
#
# Now every example below, attr_splat could safely be replaced with
# attr_accessor
alias_method :attr_accessor, :attr_splat
class Something
a method...
a method...
a method...
end class
class Foo
def self.method_added(meth); puts "Foo#method_added: #{meth}"; end
def self.singleton_method_added(meth); puts "Foo#singleton_method_added: #{meth}"; end
# Singleton
class << self
def self.method_added(meth); puts "singleton#method_added: #{meth}"; end
def self.singleton_method_added(meth); puts "singleton#singleton_method_added: #{meth}"; end
# Metasingleton
class Something
class << self
def singleton_method_added meth
puts "Self is currently #{self}, and we're defining #{meth}"
end
def a_method; end
end
end
# require 'rubygems'
# require 'evil'
($:.unshift '/Users/elliottcable/Code/refinery/lib').uniq!
require 'refinery/core_ext/class'
require 'refinery/core_ext/object'
# class UnboundMethod
# def rklass= klass
# dmeth = nil
# RubyInternal.critical {
@ELLIOTTCABLE
ELLIOTTCABLE / Object#singleton.rb
Created October 13, 2008 05:31
Object#singleton
class Object
##
# Returns the singleton class for this object.
#
# @return Class this object's singleton class
def singleton
class<<self;self;end
end
end
STDOUT.sync = true
str = [
['(o_o)', 6],
['(O_o)', 2],
['(<_<)', 1],
['(>_>)', 1],
['(<_<)', 2],
['(o_o)', 4],
['(>_>)', 3],
[' (>_>', 3],