Created
November 19, 2021 07:02
-
-
Save rozer007/22c2b406a4f7ded69aa41726b57efeb1 to your computer and use it in GitHub Desktop.
Enumerable in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1) What are enumerable in ruby? | |
ans:It is module which give the class the capabilities to use collection method. | |
Q2) What function is necessary to include in class to include enumerable? | |
ans: def each function is required to present in the class. | |
Q3) What is the function to check whether a value is present in the enumerable or not? | |
ans: We use find() function. | |
Q4) What are the which have pre defined Enumerable module. | |
ans: Hash, Array, Range, IO. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1) what will the output of this program : | |
class Enum | |
include Enumerable | |
def each | |
yield "spaghetti" | |
yield "rotti" | |
yield "salad" | |
yield "water" | |
end | |
end | |
menu=Enum.new | |
puts menu | |
a) error | |
b) rotti | |
salad | |
water | |
rotti | |
water | |
c) can't determine | |
d) enum object | |
ans: d) enum object | |
Q2) What will the output of this statement refer the previous program : | |
puts menu.drop(3) | |
a) spaghetti | |
rotti | |
salad | |
b) spaghetti | |
c) water | |
d) none of the above | |
ans: c) water | |
Q3) What will the output of this statement refer the previous program : | |
puts menu.reverse_each{|i| puts i} | |
a) error | |
b) print the elements in reverse | |
c) can't define | |
d) water | |
salad | |
rotti | |
spaghetti | |
ans: d) | |
Q4) What will the output of this statement refer the previous program : | |
puts menu.maximum() | |
a) "water" | |
b) "rotti" | |
c) error | |
d) none of the above |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment