Last active
December 31, 2015 11:59
-
-
Save teohm/7982971 to your computer and use it in GitHub Desktop.
Bracket syntax {} has higher precedence than do..end syntax [1]
[1] http://stackoverflow.com/questions/2122380/using-do-block-vs-brackets
# In this case
def outer(foo)
puts "foo: #{foo.inspect}"
yield if block_given?
end
# Use {} OK!
outer [1,2,3].map {|n| n.to_i+1}
# foo: [2, 3, 4]
# => nil
# Use do..end KO!
outer [1,2,3].map do |n|
n.to_i+1
end
# foo: #<Enumerator: [1, 2, 3]:map>
# => 1
hash.merge(hash){|_,v,_| v*2}
In Rails 4, you can remove config/database.yml
if you provide ENV['DATABASE_URL']
.
ActiveRecord, rails server
and rake db:*
all work as expected.
Except rake dbconsole
, it breaks now, but a pull request is submitted [1].
Try this runnable example:
http://runnable.com/UqwTZZACPDwtAAEj/rails-4-runs-well-without-database-yml-for-12factor
String === "foo" # true
"foo" === String # false
->(x) { x == 2 } === 2 # true
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment