Skip to content

Instantly share code, notes, and snippets.

def foo(&bar)
bar ||= lambda {|a| a}
# do something with bar
end
# Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
module RX
module Notification
class << self
def create_on_next(value)
OnNextNotification.new value
end
class Foo
attr_accessor :foo, :bar
def initialize(foo, bar)
@foo = foo
@bar = bar
end
def ==(other)
self.class == other.class &&
foo == other.foo &&
# Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
module RX
# Records information about subscriptions to and unsubscriptions from observable sequences.
class TestSubscription < Struct.new(:subscribe, :unsubscribe)
FIXNUM_MAX = (2**(0.size * 8 -2) -1)
def initialize(subscribe, unsubscribe = FIXNUM_MAX)
@jredville
jredville / regexp.rb
Created April 23, 2013 19:27
Example that Ruby case statements use `===` for comparison
puts /^(true|false)$/ === "true" #=> puts true
class Regexp
def ===(o)
false
end
end
case "true"
when /^(true|false)$/
@jredville
jredville / tmux.conf
Created March 5, 2013 18:29
My current tmux conf
# ~/.tmux.conf
#
# See the following files:
#
# /opt/local/share/doc/tmux/t-williams.conf
# /opt/local/share/doc/tmux/screen-keys.conf
# /opt/local/share/doc/tmux/vim-keys.conf
#
# URLs to read:
#
@jredville
jredville / mirror.rb
Created January 16, 2013 02:13
Back of the envelope method mirror in Ruby
class Mirror < BasicObject
def initialize(target)
@target = target
end
def method_missing(sym, *args)
@target.method(sym) rescue nil
end
def respond_to_missing?(sym, priv=false)
@jredville
jredville / hash_or_array.rb
Created October 5, 2012 20:22
Allow hash or array for a loop
def hash_or_array(obj)
obj.each do |k,v=k|
puts "k: #{k}","v: #{v}"
end
end
hash_or_array([1,2,3])
# k: 1
# v: 1
# k: 2
describe Stack do
Invariants do
If { stack.empty? }
Then { stack.depth.should == 0 }
Then { stack.should be_pushable }
ElseIf { stack.full? }
Then { stack.depth.should == stack.max_depth }
Then { stack.should_not be_pushable }
Else
Then { stack.depth.should be > 0 } # not wild about this part
module Reportable
def as_json
{:meta => meta, :report => report}
end
end
class ReportPresenter
include Reportable
def self.column(name, options={})
end