class Stud::Secret
Public Class Methods
new(secret_value)
click to toggle source
Initialize a new secret with a given value.
value - anything you want to keep secret from loggers, etc.
# File lib/stud/secret.rb, line 13 def initialize(secret_value) # Redefine the 'value' method on this instance. This exposes no instance # variables to be accidentally leaked by things like awesome_print, etc. # This makes any #value call return the secret value. (class << self; self; end).class_eval do define_method(:value) { secret_value } end end
Public Instance Methods
to_s()
click to toggle source
Emit simply “<secret>” when printed or logged.
# File lib/stud/secret.rb, line 23 def to_s return "<secret>" end
Also aliased as: inspect
value()
click to toggle source
Get the secret value.
# File lib/stud/secret.rb, line 30 def value # Nothing, this will be filled in by Secret.new # But we'll still document this so rdoc/yard know the method exists. end