Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Gibbler#digest_type, Gibbler#digest

  • Loading branch information...
commit 9da8329002742502e57cc0f6b0a490df168b6050 1 parent b04eae8
@delano authored
Showing with 29 additions and 8 deletions.
  1. +2 −0  CHANGES.txt
  2. +11 −1 lib/gibbler.rb
  3. +16 −7 try/10_standalone_try.rb
View
2  CHANGES.txt
@@ -6,6 +6,8 @@ GIBBLER, CHANGES
* CHANGE: Gibbler is now a class which supplies the default standalone usage
* CHANGE: Ruby object mixins must now be explicitly loaded via "require 'gibbler/mixins'"
* CHANGE: Removed Gibbler.enable_debug/disable_debug
+* ADDED: Gibbler.delimiter
+
#### 0.8.10 (2011-10-23) ###############################
View
12 lib/gibbler.rb
@@ -220,7 +220,9 @@ def freeze()
class Gibbler < String
include Gibbler::Digest::InstanceMethods
- attr_reader :digest
+ # Modify the digest type for this instance. See Gibbler.digest_type
+ attr_writer :digest_type
+ attr_reader :input
# Creates a digest from the given +input+. See Gibbler.digest.
#
# If only one argument is given and it's a digest, this will
@@ -233,7 +235,15 @@ def initialize *input
input.collect!(&:to_s)
super Gibbler.digest(input)
end
+ end
+ def digest_type
+ @digest_type || self.class.digest_type
end
+
+ def digest *input
+ replace Gibbler.digest(input, digest_type)
+ end
+
end
class Gibbler < String
View
23 try/10_standalone_try.rb
@@ -1,5 +1,11 @@
require 'gibbler'
+@sha256_digest = if Tryouts.sysinfo.vm == :java
+ require 'openssl'
+ OpenSSL::Digest::SHA256
+else
+ Digest::SHA256
+end
## Default delimiter
Gibbler.delimiter
@@ -27,14 +33,17 @@
g.base(36).class
#=> Gibbler
-## Can change digest type
-if Tryouts.sysinfo.vm == :java
- require 'openssl'
- Gibbler.digest_type = OpenSSL::Digest::SHA256
-else
- Gibbler.digest_type = Digest::SHA256
-end
+## Can change digest type by class
+Gibbler.digest_type = @sha256_digest
g = Gibbler.new 1, :sym, 'string', 2,3
#=> '204aacebb816bc2c8675f3490bf5a1a908988fb72f3dfd6774e963bbb9e26a26'
+## Can change digest type per instance
+Gibbler.digest_type = Digest::SHA1
+g = Gibbler.new
+g.digest_type = @sha256_digest
+g.digest 1, :sym, 'string', 2,3
+g
+#=> '204aacebb816bc2c8675f3490bf5a1a908988fb72f3dfd6774e963bbb9e26a26'
+
Gibbler.digest_type = Digest::SHA1
Please sign in to comment.
Something went wrong with that request. Please try again.