Skip to content

Instantly share code, notes, and snippets.

Working from home

Arup Rakshit aruprakshit

Working from home
Block or report user

Report or block aruprakshit

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
aruprakshit / dream_spec.rb
Last active Aug 29, 2015
Rspec to test my dream
View dream_spec.rb
describe "#dream" do
let(:user1) { User.create }
let(:user2) { User.create }
before do
# below update is on the hand of God
user1.update(:luck => true)
user2.update(:luck => false)
View Interactive Staging
Arup-iMac:yelloday shreyas$ git add -p
diff --git a/app/interactors/reporting_groups/list_colleagues.rb b/app/interactors/reporting_groups/list_colleagues.rb
index adc28af..f46f5e3 100644
--- a/app/interactors/reporting_groups/list_colleagues.rb
+++ b/app/interactors/reporting_groups/list_colleagues.rb
@@ -14,7 +14,4 @@ module ReportingGroups
- end
View user.rb
describe "#users" do
let(:sub_reporting_group) { FactoryGirl.create(:reporting_group) }
let(:reporting_group) { FactoryGirl.create(:reporting_group, reporting_group_ids: []) }
let(:user) { FactoryGirl.create(:user) }
let(:team) { FactoryGirl.create(:team) }
let(:workplace) { FactoryGirl.create(:workplace) }
context "when user belongs to either team_id or workplace_id of a parent reporting group" do
it "shouldn't include user when workplace_id not present" do
aruprakshit / belongs_to.rb
Created Jun 12, 2014
Confusion with Rails belongs_to association
View belongs_to.rb
#------model definition-----
class Book < ActiveRecord::Base
class Page < ActiveRecord::Base
belongs_to :book
class CreateBooks < ActiveRecord::Migration
def change
View users_controller.rb
# This gist is the correct one taken from Book Beginning Rails 4. The gist they mentioned in the book accidentally contains wrong
# code. Thus I created this gist, so that you can copy the code directly and move on.
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
def new
@user =
View pluck.rb
2.1.2 :008 > Employee.pluck(:age)
(0.4ms) SELECT "employees"."age" FROM "employees"
=> [19, 29, 20, 17, 25, 19, 27, nil]
2.1.2 :009 > Employee.pluck('age)
2.1.2 :010'> ^C
2.1.2 :010 > Employee.pluck(:age)
(0.4ms) SELECT "employees"."age" FROM "employees"
=> [19, 29, 20, 17, 25, 19, 27, nil]
2.1.2 :011 > Employee.pluck('age')
(0.7ms) SELECT "employees"."age" FROM "employees"
aruprakshit / respond_to.rb
Last active Aug 29, 2015
respond_to? vs respond_to_missing?
View respond_to.rb
# First check is always #respond_to? , if it returns false, then #respond_to_missing? will be called, otherwise #respond_to_missing?
# will never be called. For all regular methods( which has been created by def, define_method, in C-implementation etc), thus we get
# false, while we pass the method name to the #respond_to_missing?. Because, first check has been done inside #respond_to?, and it
# returns true. That's why second output is [true, false]. Because, #foo is a regular method.
# Now why the second output is [true, true] ? The reason, I already explained, again #baz is not a regular method, so first check in
# #respond_to? return false, thus check goes to #respond_to_missing?. As I implemented it, so as per the implementations it is giving
# true, which in turn caused #respond_to? method to returns to true.
View respond_to_missing.rb
class Wrong
def method_missing(m, *)
if m =~ /\Ahello_(.+)\z/
puts "Hello, #{$1.capitalize}"
aruprakshit /
Last active Aug 29, 2015
Playing with Enumerable#to_a

Enumerable#to_a says, that it can take arguments also. Lets try

#ArgumentError: wrong number of arguments (2 for 0)

Oops! Why then error ? Because Enumerable#to_a called actually Range#each which don't accept any arguments. Now look the below code :-

aruprakshit /
Created Jul 7, 2014
Enumerable vs Enumerator

Enumerable is a module, and Enumerator is a class. So that should tell you a lot out the the box. Enumerable is a set of behaviors and functionality you'd want to add to a class. The Enumerator class is something you get objects from itself.

You can’t perform that action at this time.