File: succ.rb

package info (click to toggle)
ruby-facets 2.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 9,824 kB
  • sloc: ruby: 25,483; xml: 90; makefile: 20
file content (44 lines) | stat: -rw-r--r-- 565 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Fixnum

  # Allows #succ to take _n_ increments.
  #
  #   3.succ(2)  #=> 5
  #
  # CREDIT: Trans

  def succ(n=1)
    self + n
  end

  # Provides #pred as the opposite of #succ.
  #
  #   3.pred(2)  #=> 1
  #
  # CREDIT: Trans

  def pred(n=1)
    self - n
  end

end

class String

  alias_method :succ1, :succ

  # Allows #succ to take _n_ step increments.
  #
  #   "abc".succ      #=> "abd"
  #   "abc".succ(4)   #=> "abg"
  #   "abc".succ(24)  #=> "aca"
  #
  # CREDIT: Trans

  def succ(n=1)
    s = self
    n.times { s = s.succ1 }
    s
  end

end