Skip to content

Instantly share code, notes, and snippets.

View kwstannard's full-sized avatar

Wolf kwstannard

  • Andros
  • New York City
View GitHub Profile
module Common
module Client
module FaradayConnection
end
end
end
module Pullson
@kwstannard
kwstannard / lookupfailure.rb
Last active August 29, 2015 14:12
Ruby inconsistency in constant lookup
module A
module B
end
end
module C
include A
puts B.inspect # => A::B
@kwstannard
kwstannard / foo.rb
Last active August 29, 2015 14:14
Ruby proxy method
class Proxy
def proxy(context, &blk)
@context = context
@blk = blk
end
def method_missing(method, *args, &blk)
__object.send(method, *args, &blk)
end
@kwstannard
kwstannard / proxy.rb
Created February 3, 2015 15:29
Ruby Proxy
class Proxy
def self.proxy(context, &blk)
p = new(context)
p.__proxy &blk
p
end
def initialize(context)
@context = context
end
@kwstannard
kwstannard / infinite.rb
Created September 14, 2015 19:35
infinite enumerator
irb(main):008:0> x = Enumerator.new(Float::INFINITY) { yield 1 }
=> #<Enumerator: #<Enumerator::Generator:0x007f85531b6360>:each>
irb(main):009:0> x.size
=> Infinity
>> be vim
Your Ruby version is 2.2.3, but your Gemfile specified 2.1.7
Vim: Caught deadly signal SEGV
Vim: Finished.
Segmentation fault: 11
# This is the default .slate file.
# If no ~/.slate file exists this is the file that will be used.
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config modalEscapeKey esc
alias modal esc,ctrl
alias mt ${modal}:toggle
### In file version
klass = Class.new do
def hi
puts 'hello'
end
end
name = __FILE__.slice(/\w*.rb$/).slice(/\w*/).camelcase
Object.const_set(name, klass)
=begin
This class allows you to condsolidate the declaration of class names into
the file name. It also handles namespacing based on the file path if you are
using Rails autoloading.
This works with the single exception of constant lookup via nesting, so you
will need to replace constants with variables and methods.
Examples:
# app/models/user.rb
Dryer.def_class(__FILE__) do
def hi
"hello world"
end
end
User.new.hi
=> "hello world"