Skip to content

Commit

Permalink
- Extended the Number.range() method to accept an optional argument f…
Browse files Browse the repository at this point in the history
…or the step number.

Example:
	range(1, 10, 2).each { |i|
		say i;	# prints: 1, 3, 5, ...
	};

	range(10, 1, -1).each { |i|
		say i;	# prints: 10, 9, 8, ...
	};
  • Loading branch information
trizen committed Sep 9, 2015
1 parent 4522d5b commit fa009ac
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/Sidef/Types/Number/Number.pm
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,11 @@ package Sidef::Types::Number::Number {
*downTo = \&downto;

sub range {
my ($self, $to) = @_;
my ($self, $to, $step) = @_;

defined($to)
? $self->to($to)
? $self->to($to, $step)
: $self->new(0)->to($self);

}

sub sqrt {
Expand Down

0 comments on commit fa009ac

Please sign in to comment.