Skip to content

Instantly share code, notes, and snippets.

View RobertDober's full-sized avatar

Robert Dober RobertDober

  • Narbonne, France
View GitHub Profile
function! s:Ruby(l1,l2,fn)
exe a:l1 . ',' . a:l2 .'!ruby -n ' . a:fn
endfunction
command! -nargs=1 -range -complete=file Ruby call s:Ruby(<line1>,<line2>,<q-args>)
Given(/^the URL of the platform$/) do
@password = something_correct
# ...
end
###
### Bad example, just to show the technique
###
Given (/^the URL of the platform with a bad password$/) do
@password = something_less_correct
@RobertDober
RobertDober / gist:168289
Created August 15, 2009 06:45
use pattern of alias, and advice
# The pattern for using alias
alias_method :__behavior__, :behavior
remove_method :behavior
define_method :behavior do
# ...
__behavior__
# ...
end
def iterate *a, &b
cons_stream a do
iterate( b[*a], &b )
end
end
#
# Pourquoi collect dans ce cas:
#
<% x.collect{ |y| %>
<% if f(y) then %>
<%= g(y) %>
<% end %>
<% } %>
#
# il serait mieux de ne pas construire cet objet Array qui ne
require 'test/unit'
class Array
def get idx
fetch idx, :undefined
# fonctionne également
# fetch( idx ){ :undefined }, mais cet idiome est plus utile en cas de traitement
# plus complex, et biensur:
# fetch( idx ) raises une exception IndexError si l'élément n'existe pas
# Hash a un #fetch pratiquement identique, il me semble plus connu
30, 33, 36, 39, 42, 52, 60, 110, 132, ?
require "rubygems"
require "shoulda"
class Test1 < Test::Unit::TestCase
context "a user" do
setup do
puts "setting up"
end
should "be true" do
puts "true"
assert true
class << Factory
alias_method :__build__, :build
def build *args, &blk
__log__( *args )
__build__( *args, &blk )
end
private
def __log__ *args
@__logfile__ ||= File::new( "xxx", "w" )
require "rubygems"
require "shoulda"
class Test1 < Test::Unit::TestCase
context "outer" do
setup do
puts "outer setup"
end
context "inner" do
setup do
puts " inner setup"