+ 2

Is there any difference between 'Proc' and 'proc'?

In the ex: greet = Proc.new do |x| puts "Welcome #{x}" end goodbye = Proc.new do |x| puts "Goodbye #{x}" end def say(arr, proc) arr.each { |x| proc.call x} people = ["David", "Amy", "John"] say(people, greet) say(people, goodbye) If i am changing any 'proc' to 'Proc' or vice-versa then it's showing error. Please someone guide me. Thanks

5th Apr 2017, 9:10 AM
Abhishek Kumar
Abhishek Kumar - avatar
6 Réponses
+ 8
Ruby is a sensitive cased language which means case and Case are not the same, Its the same when declaring a variable, or getting the Proc. You cant just do proc.new do instead you need Proc.new do :D
5th Apr 2017, 1:33 PM
MrCoder
MrCoder - avatar
+ 5
proc is a parameter of the functions "say" so it is not a Proc.:D
5th Apr 2017, 2:05 PM
MrCoder
MrCoder - avatar
+ 5
My pleasure :D
5th Apr 2017, 11:04 PM
MrCoder
MrCoder - avatar
+ 3
MrCoder, oh ya i got it now, Thanks (y)
5th Apr 2017, 2:14 PM
Abhishek Kumar
Abhishek Kumar - avatar
+ 2
MrCoder Thanks for your answer but they used 'Proc' and 'proc' in the same program. Why so?
5th Apr 2017, 2:02 PM
Abhishek Kumar
Abhishek Kumar - avatar
0
Proc is a class, it's a constant, proc is just a parameter.
5th Apr 2017, 2:22 PM
Steven Wang
Steven Wang - avatar