ruby-block Questions
4
Solved
I'm learning the details of how each works in ruby, and I tried out the following line of code:
p [1,2,3,4,5].each { |element| el }
And the result is an array of
[1,2,3,4,5]
Why is the return val...
Turret asked 22/7, 2012 at 0:27
10
Solved
I am trying to understand blocks and yield and how they work in Ruby.
How is yield used? Many of the Rails applications I've looked at use yield in a weird way.
Can someone explain to me or show ...
Calamitous asked 18/6, 2010 at 1:34
1
Solved
I have a method and in order to check whether it is being passed a block, I do the following:
if block_given?
res = yield(array[i], array[i+1])
else
res = array[i] - array[i+1]
end
However R...
Forficate asked 11/2, 2018 at 11:29
2
Solved
I want to check whether the block is called in my function using rspec. Below is my code:
class SP
def speak(options={},&block)
puts "speak called"
block.call()
rescue ZeroDivisionError =...
Femme asked 16/6, 2017 at 21:13
1
Solved
I'm doing the following:
array_variable = collection.map do |param|
some value with param
end
return array_variable.compact
Can I call map and compact in one statement somehow, so I can return ...
Karyokinesis asked 8/6, 2017 at 11:12
5
Solved
I'm trying to re-use an html component that i've written that provides panel styling. Something like:
<div class="v-panel">
<div class="v-panel-tr"></div>
<h3>Some Title...
Obsolesce asked 1/6, 2010 at 15:36
3
Solved
I have a ruby method that needs to check if a block was passed to it.
A colleague is suggesting that simply checking if block.nil? is slightly faster in performance and works for named blocks. Thi...
Shoshanashoshanna asked 23/11, 2016 at 10:24
1
© 2022 - 2024 — McMap. All rights reserved.