aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/secure_random.rb
diff options
context:
space:
mode:
authorJosep M. Bach <josep.m.bach@gmail.com>2010-08-14 17:52:52 +0200
committerXavier Noria <fxn@hashref.com>2010-08-15 02:22:38 +0200
commit9f9a02af86dee5372aae2bd84a5220245bee8706 (patch)
treed3e0d6291d43a15ca9f062f8737f6751921bf4e4 /activesupport/lib/active_support/secure_random.rb
parente8ef58a697c4af99a7db44267cf6d975fb5d6091 (diff)
downloadrails-9f9a02af86dee5372aae2bd84a5220245bee8706.tar.gz
rails-9f9a02af86dee5372aae2bd84a5220245bee8706.tar.bz2
rails-9f9a02af86dee5372aae2bd84a5220245bee8706.zip
Whitespace and example identation
Diffstat (limited to 'activesupport/lib/active_support/secure_random.rb')
-rw-r--r--activesupport/lib/active_support/secure_random.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/secure_random.rb b/activesupport/lib/active_support/secure_random.rb
index 73344498cb..488a7e14a7 100644
--- a/activesupport/lib/active_support/secure_random.rb
+++ b/activesupport/lib/active_support/secure_random.rb
@@ -46,8 +46,10 @@ module ActiveSupport
# p SecureRandom.random_bytes(10) # => "\016\t{\370g\310pbr\301"
# p SecureRandom.random_bytes(10) # => "\323U\030TO\234\357\020\a\337"
# ...
+ #
module SecureRandom
- # SecureRandom.random_bytes generates a random binary string.
+
+ # Generates a random binary string.
#
# The argument n specifies the length of the result string.
#
@@ -56,6 +58,7 @@ module ActiveSupport
#
# If secure random number generator is not available,
# NotImplementedError is raised.
+ #
def self.random_bytes(n=nil)
n ||= 16
@@ -124,7 +127,7 @@ module ActiveSupport
raise NotImplementedError, "No random device"
end
- # SecureRandom.hex generates a random hex string.
+ # Generates a random hex string.
#
# The argument n specifies the length of the random length.
# The length of the result string is twice of n.
@@ -134,11 +137,12 @@ module ActiveSupport
#
# If secure random number generator is not available,
# NotImplementedError is raised.
+ #
def self.hex(n=nil)
random_bytes(n).unpack("H*")[0]
end
- # SecureRandom.base64 generates a random base64 string.
+ # Generates a random base64 string.
#
# The argument n specifies the length of the random length.
# The length of the result string is about 4/3 of n.
@@ -148,11 +152,12 @@ module ActiveSupport
#
# If secure random number generator is not available,
# NotImplementedError is raised.
+ #
def self.base64(n=nil)
[random_bytes(n)].pack("m*").delete("\n")
end
- # SecureRandom.random_number generates a random number.
+ # Generates a random number.
#
# If an positive integer is given as n,
# SecureRandom.random_number returns an integer:
@@ -161,6 +166,7 @@ module ActiveSupport
# If 0 is given or an argument is not given,
# SecureRandom.random_number returns an float:
# 0.0 <= SecureRandom.random_number() < 1.0.
+ #
def self.random_number(n=0)
if 0 < n
hex = n.to_s(16)