SingleForwardable
can be used to setup delegation at the object level as well.
printer = String.new printer.extend SingleForwardable # prepare object for delegation printer.def_delegator "STDOUT", "puts" # add delegation for STDOUT.puts() printer.puts "Howdy!"
Also, SingleForwardable
can be used to set up delegation for a Class
or Module
.
class Implementation def self.service puts "serviced!" end end module Facade extend SingleForwardable def_delegator :Implementation, :service end Facade.service #=> serviced!
If you want to use both Forwardable and SingleForwardable
, you can use methods def_instance_delegator and def_single_delegator
, etc.
When mathn is required, the Math
module changes as follows:
Standard Math
module behaviour:
Math.sqrt(4/9) # => 0.0 Math.sqrt(4.0/9.0) # => 0.666666666666667 Math.sqrt(- 4/9) # => Errno::EDOM: Numerical argument out of domain - sqrt
After require ‘mathn’, this is changed to:
require 'mathn' Math.sqrt(4/9) # => 2/3 Math.sqrt(4.0/9.0) # => 0.666666666666667 Math.sqrt(- 4/9) # => Complex(0, 2/3)
The Math
module contains module functions for basic trigonometric and transcendental functions. See class Float
for a list of constants that define Ruby’s floating point accuracy.
Domains and codomains are given only for real (not complex) numbers.
A module to implement the Linda distributed computing paradigm in Ruby.
See the sample/drb/ directory in the Ruby distribution, from 1.8.2 onwards.
The top-level class representing any ASN.1 object. When parsed by ASN1.decode
, tagged values are always represented by an instance of ASN1Data
.
ASN1Data
for parsing tagged values When encoding an ASN.1 type it is inherently clear what original type (e.g. INTEGER, OCTET STRING etc.) this value has, regardless of its tagging. But opposed to the time an ASN.1 type is to be encoded, when parsing them it is not possible to deduce the “real type” of tagged values. This is why tagged values are generally parsed into ASN1Data
instances, but with a different outcome for implicit and explicit tagging.
An implicitly 1-tagged INTEGER value will be parsed as an ASN1Data
with
tag
equal to 1
tag_class
equal to :CONTEXT_SPECIFIC
value
equal to a String
that carries the raw encoding of the INTEGER.
This implies that a subsequent decoding step is required to completely decode implicitly tagged values.
An explicitly 1-tagged INTEGER value will be parsed as an ASN1Data
with
tag
equal to 1
tag_class
equal to :CONTEXT_SPECIFIC
value
equal to an Array
with one single element, an instance of OpenSSL::ASN1::Integer
, i.e. the inner element is the non-tagged primitive value, and the tagging is represented in the outer ASN1Data
int = OpenSSL::ASN1::Integer.new(1, 0, :IMPLICIT) # implicit 0-tagged seq = OpenSSL::ASN1::Sequence.new( [int] ) der = seq.to_der asn1 = OpenSSL::ASN1.decode(der) # pp asn1 => #<OpenSSL::ASN1::Sequence:0x87326e0 # @infinite_length=false, # @tag=16, # @tag_class=:UNIVERSAL, # @tagging=nil, # @value= # [#<OpenSSL::ASN1::ASN1Data:0x87326f4 # @infinite_length=false, # @tag=0, # @tag_class=:CONTEXT_SPECIFIC, # @value="\x01">]> raw_int = asn1.value[0] # manually rewrite tag and tag class to make it an UNIVERSAL value raw_int.tag = OpenSSL::ASN1::INTEGER raw_int.tag_class = :UNIVERSAL int2 = OpenSSL::ASN1.decode(raw_int) puts int2.value # => 1
int = OpenSSL::ASN1::Integer.new(1, 0, :EXPLICIT) # explicit 0-tagged seq = OpenSSL::ASN1::Sequence.new( [int] ) der = seq.to_der asn1 = OpenSSL::ASN1.decode(der) # pp asn1 => #<OpenSSL::ASN1::Sequence:0x87326e0 # @infinite_length=false, # @tag=16, # @tag_class=:UNIVERSAL, # @tagging=nil, # @value= # [#<OpenSSL::ASN1::ASN1Data:0x87326f4 # @infinite_length=false, # @tag=0, # @tag_class=:CONTEXT_SPECIFIC, # @value= # [#<OpenSSL::ASN1::Integer:0x85bf308 # @infinite_length=false, # @tag=2, # @tag_class=:UNIVERSAL # @tagging=nil, # @value=1>]>]> int2 = asn1.value[0].value[0] puts int2.value # => 1
Stores multipart form data. FormData
objects are created when WEBrick::HTTPUtils.parse_form_data
is called.
Net::IMAP::BodyTypeAttachment
represents attachment body structures of messages.
Returns the content media type name.
Returns nil
.
Returns a hash that represents parameters.
Returns false.
An InstalledSpecification
represents a gem that is already installed locally.
The StaticSet
is a static set of gem specifications used for testing only. It is available by requiring Gem::TestCase
.
Root of the HTTP status class hierarchy
Common validators of number and nz_number types
Element
used to describe an Atom
date and time in the ISO 8601 format
Examples:
2013-03-04T15:30:02Z
2013-03-04T10:30:02-05:00
Raised by Encoding
and String methods when the source encoding is incompatible with the target encoding.
This exception is raised if a generator or unparser error occurs.