Joined February 2013
·

Jaryl Sim

Founder at Tinkerbox
·
Singapore
·
·
·

Posted to Ruby : block as parameter 5 months ago

It's not really strange, if you have used the each method, you are straight up using blocks. What you might be missing here is that you can do the iteration within your own method, like so:

def foo_m(collection, &block)
  collection.each do |i|
    if (i % 2) == 0
      puts "hooray"
    else
      yield
    end
  end
end

Which you then use like this:

foo_m([1,2,3,4,5]) do
  puts "something is odd here"
end
Posted to Asset Pipeline helpers over 1 year ago

You can also use the CSS/SCSS helpers, image-url, image-path so you don't need to use the embedded ruby syntax. From the official guide:

When using the asset pipeline, paths to assets must be re-written and sass-rails provides -url and -path helpers (hyphenated in Sass, underscored in Ruby) for the following asset classes: image, font, video, audio, JavaScript and stylesheet.

image-url("rails.png") becomes url(/assets/rails.png)
image-path("rails.png") becomes "/assets/rails.png".

The more generic form can also be used but the asset path and class must both be specified:

asset-url("rails.png", image) becomes url(/assets/rails.png)
asset-path("rails.png", image) becomes "/assets/rails.png"

Posted to .gitignore not working over 1 year ago

I believe this happens when you try to ignore a file that's already in the repository.

I used webmock for mocking external requests, so I had a problem with it blocking coveralls and codeclimate from submitting the reports, so I added this in:

RSpec.configure do |config|
  ...
  config.after(:suite) do
    WebMock.disable!
  end
end

In addition, I amended your code such that only if the ENV variable is provided for the respective services do I add it to the formatter. See gist: https://gist.github.com/jaryl/6554599#file-spec_helper-rb

Achievements
51 Karma
3,092 Total ProTip Views