addis_a
1
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
Hello,
Im trying to do this exercise :
- Create a method,
greeter
, that
takes no arguments and yield
s to a block.
- Create a Proc,
phrase
, that
puts "Hello there!"
. Pass this
to greeter
instead of a block.
(Don't forget to pass &phrase
instead of just phrase
!)
Till now I have this :
def greeter
yield
end
phrase = Proc.new do
puts "Hello there!"
end
But I do not see where and how I must use the &phrase
?
Can someone help me figure out how to solve this ?
Roelof
roelof
2
On Wed, Nov 19, 2014 at 1:16 PM, Roelof W. [email protected] wrote:
def greeter
yield
end
phrase = Proc.new do
puts “Hello there!”
end
But I do not see where and how I must use the &phrase ?
Can someone help me figure out how to solve this ?
It’s all in the description of task 2. You pass something to a method
but…
Kind regards
robert
roelof
3
greeter &phrase
I recommend you to read about blocks and Procs. This link may be useful
but
there should be better ones:
http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Method_Calls#The_ampersand_.28.26.29
2014-11-19 9:16 GMT-03:00 Roelof W. [email protected]:
roelof
4
On Wed, Nov 19, 2014 at 1:28 PM, Juanjo C. [email protected] wrote:
I think it’s not so helpful to just post the answer when someone is
trying to learn.
Cheers
robert
roelof
5
Yep. I found it myself that the answer
is greeter(&phrase)
Roelof
Juanjo C. schreef op 19-11-2014 13:28:
2014-11-19 9:16 GMT-03:00 Roelof W.
<[email protected]>:
Hello,
Im trying to do this exercise :
- Create a method,
greeter
, that takes
no arguments and yield
s to
a block.
- Create a Proc,
phrase
, that puts
"Hello
there!"
. Pass this to greeter
instead of a block. (Don't forget to pass
&phrase
instead of just phrase
!)
Till now I have this :
def greeter
?????? yield
end
phrase = Proc.new do
?????? puts "Hello there!"
end
But I do not see where and how I must use the
&phrase?? ?
Can someone help me figure out how to solve this ?
Roelof
--
roelof
6
Did you read the article I pointed out? If you’re learning, instead of
just
make the code work, you should worry to understand why it did work.
Greets,
PS: Sorry Robert about the direct response.
2014-11-19 9:48 GMT-03:00 Roelof W. [email protected]:
roelof
7
Yes. I did. That's whty I figured the
solution myself.
Roelof
Juanjo C. schreef op 19-11-2014 13:55:
Did you read the article I pointed out? If you're
learning, instead of just make the code work, you should worry
to understand why it did work.
Greets,
PS: Sorry Robert about the direct response.
2014-11-19 9:48 GMT-03:00 Roelof W.
<[email protected]>:
Yep. I found it myself that the answer is
greeter(&phrase)
Roelof
Juanjo C. schreef op 19-11-2014 13:28:
2014-11-19 9:16 GMT-03:00
Roelof W.
<[email protected]>:
Hello,
Im trying to do this exercise :
- Create a method,
greeter
,
that takes no arguments and
yield
s
to a block.
- Create a Proc,
phrase
,
that puts "Hello there!"
.
Pass this to greeter
instead of a block. (Don't forget to
pass &phrase
instead
of just phrase
!)
Till now I have this :
def greeter
?????? yield
end
phrase = Proc.new do
?????? puts "Hello there!"
end
But I do not see where and how I must use
the &phrase?? ?
Can someone help me figure out how to
solve this ?
Roelof
--
--