Difference between revisions of "Powers Of 2 Range Assignment"
Jump to navigation
Jump to search
(Created page with "=Reference= ==Ruby== : [https://apidock.com/ruby/Kernel/block_given%3F block_given?] : [https://apidock.com/ruby/Proc/yield yield] =Code to Implement= ==PowersOfTwoRange== {{...") |
|||
Line 6: | Line 6: | ||
=Code to Implement= | =Code to Implement= | ||
==PowersOfTwoRange== | ==PowersOfTwoRange== | ||
− | {{RubyToImplement|powers_of_two_range|powers_of_two_range|PowersOfTwoRange|Object|initialize(maximum, inclusive: false)<br/>each() | + | {{RubyToImplement|powers_of_two_range|powers_of_two_range|PowersOfTwoRange|Object|initialize(maximum, inclusive: false)<br/>each<br/>each_with_index}} |
+ | ===initialize(maximum, inclusive: false)=== | ||
+ | hang onto enough information in instance variables to support each and each_with_index | ||
+ | ===each=== | ||
+ | if a block is given, repeatedly yield with appropriate value. | ||
+ | |||
+ | otherwise, return an enum via to_enum. | ||
+ | |||
+ | ===each_with_index=== | ||
+ | if a block is given, repeatedly yield with appropriate value and its index. | ||
+ | |||
+ | otherwise, return an enum via to_enum. | ||
==Unit Test== | ==Unit Test== | ||
{{RubyUnitTest|powers_of_two_range|powers_of_two_range}} | {{RubyUnitTest|powers_of_two_range|powers_of_two_range}} |
Revision as of 15:44, 11 April 2022
Contents
Reference
Ruby
Code to Implement
PowersOfTwoRange
file: | src/main/ruby/powers_of_two_range/powers_of_two_range.rb | |
class: | PowersOfTwoRange | |
superclass: | Object | |
methods: | initialize(maximum, inclusive: false) each each_with_index |
initialize(maximum, inclusive: false)
hang onto enough information in instance variables to support each and each_with_index
each
if a block is given, repeatedly yield with appropriate value.
otherwise, return an enum via to_enum.
each_with_index
if a block is given, repeatedly yield with appropriate value and its index.
otherwise, return an enum via to_enum.
Unit Test
file: | src/test/ruby/powers_of_two_range/powers_of_two_range.rb | UnitTest |
note: ensure that you have removed all printing to receive credit for any assignment.