Skip to content

Instantly share code, notes, and snippets.

def self.some_func
end
# now we can call this at the top-level
p some_func #=> nil
# without polluting Object
p Object.new.respond_to?(:some_func, true) #=> false
def some_object_polluting_func
module MyApp
module Deeply
module Nested
module Namespace
class Useful
end
class AlsoUseful
end
module CallInstance
def call(*args, &block)
new(*args, &block).call
end
alias_method :[], :call
end
p RUBY_VERSION #=> "2.0.0"
require 'adamantium'
require 'adamantium/version' # not required by default, oops!
p Adamantium::VERSION #=> "0.1.0"
class Something
include Adamantium
end
@misfo
misfo / bm_deep_freeze.rb
Created September 17, 2013 21:31
Testing IceNine.deep_freeze performanc
require 'benchmark'
require 'ice_nine'
def self.nested(depth, width, array_length)
hash = {}
1.upto(width) do |n|
hash[n.to_s] = n.to_s
end
require 'unparser'
original_verbosity = $VERBOSE
$VERBOSE = nil
Unparser::Emitter::REGISTRY = Unparser::Emitter::REGISTRY.dup
$VERBOSE = original_verbosity
module Rbfmt
module Emitters
# * Uses parens if the source did
@misfo
misfo / eli.rb
Created October 19, 2012 20:36
Eli's first line of code
jkjkio,6734t556b n b234534
@misfo
misfo / funcs.rb
Created August 13, 2012 13:11
testing module functions in Ruby
module Funcs
module_function
# functions ...
end
user=> (take 10 (filter #(and (= 1 (mod % 2) (mod % 3) (mod % 4) (mod % 5) (mod % 6)) (= (mod % 7) 0)) (range)))
(301 721 1141 1561 1981 2401 2821 3241 3661 4081)
module Functions
module_function
def state
@state || ":-)"
end
def make_stateful!
@state = ":-("