⌘T | go to file |
⌘⌃P | go to project |
⌘R | go to methods |
⌃G | go to line |
⌘KB | toggle side bar |
⌘⇧P | command prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use .transpose to 'unzip' an array of arrays | |
[ [ 1, 'a' ], [ 2, 'b' ], [ 3, 'c' ] ].transpose # => [ [ 1, 2, 3 ], [ 'a', 'b', 'c' ] ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print a 32-bit integer as an 8 character hex string | |
"%08X" % 65535 # => "0000FFFF" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'active_support' | |
module Attrs | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def add_public_accessor(name) | |
add_accessor(name) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run from the console of your Rails project | |
param_filter = ActionDispatch::Http::ParameterFilter.new([:foo, :bar]) | |
param_filter.filter("foo" => "hi") # => {"foo"=>"[FILTERED]"} | |
param_filter.filter("BAR" => "123") # => {"BAR"=>"[FILTERED]"} | |
param_filter.filter("Food" => "nachos") # => {"Food"=>"[FILTERED]"} | |
param_filter.filter("hobart" => "australia") # => {"hobart"=>"[FILTERED]"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe MessageReceiver do | |
context 'with a hello message' do | |
let(:message) { "hello" } | |
it 'responds accordingly' do | |
subject.receive(message).should == 'is it me your looking for?' | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Monad | |
def self.unit(value) | |
monad = new | |
monad.define_singleton_method(:bind) { |func, *args| func.call(*([value] + args)) } | |
monad | |
end | |
def lift(name, func, *args) | |
define_singleton_method(name) { Monad.unit(bind(func, args)) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"J\u00e4germeister" # => "Jägermeister" | |
"Caf\u00e9" # => "Café" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'forwardable' | |
class Foo | |
extend Forwardable | |
# Note: def_delegators, not def_delegator | |
def_delegators :ar, :size, :map | |
def ar | |
[1, 2, 3] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# require 'active_support' | |
# Monday, August 3, 2014 | |
today = Date.today #=> Mon, 04 Aug 2014 | |
Date.yesterday #=> Sun, 03 Aug 2014 | |
Date.tomorrow #=> Tue, 05 Aug 2014 | |
# this week | |
today.beginning_of_week #=> Mon, 04 Aug 2014 |
OlderNewer