Skip to content

Instantly share code, notes, and snippets.

View bagwanpankaj's full-sized avatar

Pankaj Bagwan bagwanpankaj

View GitHub Profile
@bagwanpankaj
bagwanpankaj / base_template.rb
Created April 30, 2010 04:50
Rails Template
run "echo TODO > README"
if yes?("Do you want to use RSpec(yes/no)")
plugin "rspec", :git => "git://github.com/dchelimsky/rspec.git"
plugin "rspec-rails", :git => "git://github.com/dchelimsky/rspec-rails.git"
generate :rspec
elsif yes?("Do you want to use shoulda and factory girl(yes/no)")
gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com"
gem "factory_girl", :source => "http://gemcutter.org"
end
@bagwanpankaj
bagwanpankaj / webrat_extension.rb
Created October 17, 2010 12:41
Webrat Step extension
#Created By Bagwan Pankaj (RailsJaipur) “http://bagwanpankaj.com/”
#This file is an extension of default webrat steps. some of the webrat steps have been extended
#in this file so that one need not to write unrequired steps.
#Extends default
#USE: When I follow //
When /^I follow \/([^\/]*)\/$/ do |regexp_link|
click_link(regexp_link)
end
#USE: When I follow // within ""
@bagwanpankaj
bagwanpankaj / meta_define_method.rb
Created October 19, 2010 08:58
Ruby MetaProgramming Samples
class Testt
define_method :foo do
"welcome"
end
end
Testt.new().foo
=> "welcome"
module Hello
define_method :foo do |name|
@bagwanpankaj
bagwanpankaj / gmail_action_mailer_conf.yml
Created October 19, 2010 09:06
Gmail SMTP Conf with Rails
development:
enable_starttls_auto: true
address: "smtp.gmail.com"
port: 587
domain: 'http://'
authentication: plain
user_name: "user@domain_name"
password: your-password
production:
@bagwanpankaj
bagwanpankaj / Shortly.rb
Created January 26, 2011 17:38
Shortly Blog entries
gem install shortly [-v=<your-version-of-choice>]
#or for Bundler user
gem 'shortly' #then
bundle install
@bagwanpankaj
bagwanpankaj / monkey_patching.rb
Created January 29, 2011 05:53
Monkey Patching done right
#first we create a subclass of class string
class MyString < String
end
MyString.new
# => ""
#now we are going to override this method by some Ruby magic
MyString.class_eval do
def empty?
@bagwanpankaj
bagwanpankaj / dafault_proc_1.rb
Created January 29, 2011 06:38
default_proc for Hash
hs = Hash.new
hs[:absent_key]
# => {}
hs[:absent_key][:some_other_key]
# NoMethodError: undefined method `[]' for nil:NilClass
@bagwanpankaj
bagwanpankaj / ruby_19_hash.rb
Created January 30, 2011 17:25
Changes in Ruby 1.9
#Hash becomes more compatible
#Do you know you can write hash in ruby like you do in other languages.
hs = {first: 1, second: 2, third: 3, fourth: 4}
# => {:first=>1, :second=>2, :third=>3, :fourth=>4}
hs.class
# => Hash
@bagwanpankaj
bagwanpankaj / ruby_19_default_args.rb
Created February 7, 2011 18:05
Ruby 1.9 Default Arguments
#rvm use 1.9.2
#ruby19 allows default arguments to be in beginning of method's arguments.
def test_default_argument(a = 1, b)
"a:#{a},b:#{b}"
end
test_default_argument(3)
#=> "a:1,b:3"
@bagwanpankaj
bagwanpankaj / ruby_19_spalt_args.rb
Created February 7, 2011 18:28
Ruby 1.9 Defining Spalt arguments
We couldn’t find that file to show.