Check all that apply How do Ruby iterators differ from java
Check all that apply:
 
 How do Ruby iterators differ from java iterators?
 A. Unlike Java iterators, Ruby iterators usually avoid the need to use an index variable (e.g., i) inside the body of the iteration.
 B. Ruby has multiple methods defined over system classes that act as iterators.
 C. Ruby iterators work \"from the outside in\" instead of \"from the inside out.\"
 D. Ruby has an iterator that iterates over both key and value in a hash.
Solution
Ruby is an interpreted language and interpreted languages will tend to be slower than compiled ones because in interpreted languages most of its implementations execute instructions directly, without previously compiling a program into machine-language instructions
Ruby is interpreted java is compiled.
In ruby we will write like: > ruby my_program.rb
Whereas in java it will be like: >javac MyProgram.java
>java MyProgram.
Java is great for its performances. Ruby is great for its terseness,readability and flexibility.
A. Unlike Java iterators, Ruby iterators usually avoid the need to use an index variable (e.g., i) inside the body of the iteration.
An iterator is a looping construct in Ruby. It uses method syntax,the variable \"i\" starts at 0 and is incremented by 1 on each pass through the loop.
Based on Ruby2
Ruby program that uses times
# Use a times-loop.
4.times do
puts \"a\"
end
# Use a times iterator with an iteration variable.
5.times do |i|
puts i
end
output:
a
a
a
0
1
2
B. A Ruby iterator is simply a method that can invoke a block of code in a conventional way.
Within the method, the block may be invoked, almost as if it were a method itself, using the yield statement. Whenever a yield is executed, it invokes the code in the block. When the block exits, control picks back up immediately after the yield.
C. All member variables are private. From the outside, you access everything via methods. There are public, private and protected methods.
D. Value is a Hash to so you need iterate on it or you can get only values:-
h.each do |key, value|
puts key
value,each do |k,v|
puts k
puts v
end
end


