Skip to content

Instantly share code, notes, and snippets.

#Understanding blocks, Procs and lambdas. I think blocks, Procs and lambdas are working in a really counter-intuitive way when you
first try to understand how they work, and most of the (amazing) resources one can find online
are too complicated to allow to understand how they work without frustration...

So here is my take on it; I'll try to make it as simple and concise as possible,
and will focus on how it is used, instead of how it works under the hood.

##Blocks A block is simply a piece of code that will (usually) execute something;

Automated Testing.

Testing is helpful for ensuring that your code runs (driver code). This is to make sure that current features work, old features still work, and future work will be easily tested. By default, every Rails application has three environments: development, test, and production.

Rails offers three kinds of testing:

  • Unit tests: 
In the context of Rails, unit tests are meant primarily to cover the domain logic in your models, which include things like validations, calculations, search methods, and any other interesting functionality that your models implement.
  • Functional tests: These provide a way to verify that the actions for a single controller are working as expected, and allow you to do things such as post data to a specific action and verify the correct response is returned
  • Integration tests: Any given session with a Rails application will span across several models and controllers. Integration tests provide a way to test those kinds of interactions. Essentia
@carolineartz
carolineartz / .bash_profile
Created February 17, 2014 18:03
someone’s bash profile
export PATH="/usr/local/bin:$PATH"
export PGHOST=localhost
# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
export GIT_PS1_SHOWDIRTYSTATE=true
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`

Mar 2nd, 2009

An efficient workflow for developers in Agile teams that handles features and bugs while keeping a clean and sane history.

At Hashrocket we use git both internally and in our Agile mentoring and training. Git gives us the flexibility to design a version control workflow that meets the needs of either a fully Agile team or a team

# CLOSURES IN RUBY Paul Cantrell http://innig.net
# Email: username "cantrell", domain name "pobox.com"
# I recommend executing this file, then reading it alongside its output.
#
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments,
# then trying to guess the output of the code!
# A closure is a block of code which meets three criteria:
#

Ruby is an awesome piece of creation, Everyday I’m learning and discovering ruby in lot different and better way. just like other days today i dug more into how ruby closures work. here is my brief explanation after reading about ruby closures. thanks to the author for his wonderful writeup.

As we know ruby does lotta stuffs with closure, like in array iteration we are using closures in everywhere. Ruby has 4 type of closures – Block, Procs, Lambda and Method. I’m trying to explain them in brief. So i could use this post as my future reminder.

Block

It’s used with ‘&’ sign prefixed variable also executes using yield or *.call.

def say_hi_to(&block) puts "Say hi #{block.call}"

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@carolineartz
carolineartz / gist:9061501
Last active September 25, 2015 13:29 — forked from AMHOL/tricks.md
#####################################################
### USEFUL TRICKS ###################################
#####################################################
# Array.reduce will inject and initial value into a block and pass in each value in turn
# until all values in the array has been iterated i.e
([1] * 10).reduce(0) { |total, current_value| total + current_value } #= 10
# Inject does the same
([1] * 10).inject(0) { |total, current_value| total + current_value } #= 10

Understanding Ruby Blocks, Procs and Lambdas

Blocks, Procs and lambdas (referred to as closures in Computer Science) are one of the most powerful aspects of Ruby, and also one of the most misunderstood. This is probably because Ruby handles closures in a rather unique way. Making things more complicated is that Ruby has four different ways of using closures, each of which is a tad bit different, and sometimes nonsensical. There are quite a few sites with some very good

# YOUR NAMES: Caroline Artz (Went solo, didn't have an opportunity for a GPS for this)
require_relative 'state_data' #requires (links) the content of the file state_data (here its in the same directory)
class VirusPredictor
attr_reader :population #for bonus
def self.state_report(data)
data.each do |state, state_data|
VirusPredictor.new(state, state_data).virus_effects