Skip to content

Instantly share code, notes, and snippets.

View jaredatron's full-sized avatar

Jared Grippe jaredatron

View GitHub Profile
require 'rubygems'
require 'activesupport'
class Array
def to_proc
procs = self.clone
lambda { |object, *args|
procs.inject(object){ |object, proc|
proc.to_proc.call(object, *args)
}
def convert_value(value)
case value
when Hash
value.with_indifferent_access
when Array
# value.collect { |e| e.is_a?(Hash) ? e.with_indifferent_access : e }
value.include(WithIndifferentHashes)
else
value
end
class Hash
# Like has_key? but accepts an list of keys and returns true of self has every
# key in the array
def has_keys?(key, *other_keys)
other_keys.unshift key
other_keys.flatten.all?{ |k| self.has_key? k }
end
# Like has_key? but accepts a list of keys and returns true of self has any
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:EDITOR] = :mate
require 'rubygems'
require 'utility_belt'
%w(google interactive_editor command_history with).each{ |t| require "utility_belt/#{t}" }
require 'wirble'
require 'pp'
WIRBLE_OPTIONS = {
class Regexp
def to_proc
lambda{|*args| (matches = args.shift.match(self)) ? matches.to_a.first : nil}
end
end
example = %w(love me inside your face)
puts example.find_all(&/^l|y|f/).inspect
puts example.map(&/^l|y|f/).inspect
class Regexp
def to_proc
lambda {|arg| match(arg)}
endhttp://gist.github.com/images/modules/gist/save_button.png
end
puts /whatever/.to_proc.call(5,6)
# => untitled:3: warning: multiple values for a block parameter (2 for 1)
diff --git a/features/step_definitions/challenge_creation_wizard_page_steps.rb b/features/step_definitions/challenge_creation_wizard_page_steps.rb
index 5a49295..477bb46 100644
--- a/features/step_definitions/challenge_creation_wizard_page_steps.rb
+++ b/features/step_definitions/challenge_creation_wizard_page_steps.rb
@@ -3,7 +3,7 @@ When /^I enter "([^\"]+)" into the game field$/ do |game_name|
fill_in("challenge_game_id", :with => game.param)
end
-When /^I enter that game''?s title into the game field$/ do
+When Regexp.new('^I enter that game\'s title into the game field$') do
class Object
def tell(method, *args)
send(method, *args)
self
end
alias_method :returning_self, :tell
end
puts [[1,2,[1,2]]].compact!.inspect
puts [[1,2,[1,2]]].tell(:compact!).inspect
class Object
def tell(method, *args)
send(method, *args)
self
end
alias_method :returning_self, :tell
end
puts [[1,2,[1,2]]].compact!.inspect
puts [[1,2,[1,2]]].tell(:compact!).inspect
class Object
define_method :returning_self do
ReturningSelf.new(self)
end
class ReturningSelf
private *instance_methods.select { |m| m !~ /(^__|^\W|^binding$)/ }
def initialize(subject)
@subject = subject
end
def method_missing(sym, *args, &blk)