Invoked as a callback whenever a singleton method is removed from the receiver.
module Chatty def Chatty.singleton_method_removed(id) puts "Removing #{id.id2name}" end def self.one() end def two() end def Chatty.three() end class << self remove_method :three remove_method :one end end
produces:
Removing three Removing one
Returns the destination encoding name as a string.
Returns the destination encoding name as a string.
Calls the block, if given, with each element of self
; returns a new Array whose elements are the return values from the block:
a = [:foo, 'bar', 2] a1 = a.map {|element| element.class } a1 # => [Symbol, String, Integer]
Returns a new Enumerator
if no block given:
a = [:foo, 'bar', 2] a1 = a.map a1 # => #<Enumerator: [:foo, "bar", 2]:map>
Calls the block, if given, with each element; replaces the element with the block’s return value:
a = [:foo, 'bar', 2] a.map! { |element| element.class } # => [Symbol, String, Integer]
Returns a new Enumerator
if no block given:
a = [:foo, 'bar', 2] a1 = a.map! a1 # => #<Enumerator: [:foo, "bar", 2]:map!>
Calls the block, if given, with each element of self
; returns a new Array containing those elements of self
for which the block returns a truthy value:
a = [:foo, 'bar', 2, :bam] a1 = a.select {|element| element.to_s.start_with?('b') } a1 # => ["bar", :bam]
Returns a new Enumerator
if no block given:
a = [:foo, 'bar', 2, :bam] a.select # => #<Enumerator: [:foo, "bar", 2, :bam]:select>
Calls the block, if given with each element of self
; removes from self
those elements for which the block returns false
or nil
.
Returns self
if any elements were removed:
a = [:foo, 'bar', 2, :bam] a.select! {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
Returns nil
if no elements were removed.
Returns a new Enumerator
if no block given:
a = [:foo, 'bar', 2, :bam] a.select! # => #<Enumerator: [:foo, "bar", 2, :bam]:select!>
Returns a new Complex object formed from the arguments, each of which must be an instance of Numeric
, or an instance of one of its subclasses: Complex, Float
, Integer
, Rational
; see Rectangular Coordinates:
Complex.rect(3) # => (3+0i) Complex.rect(3, Math::PI) # => (3+3.141592653589793i) Complex.rect(-3, -Math::PI) # => (-3-3.141592653589793i)
Complex.rectangular is an alias for Complex.rect.
Returns the array [self.real, self.imag]
:
Complex.rect(1, 2).rect # => [1, 2]
If self
was created with polar coordinates, the returned value is computed, and may be inexact:
Complex.polar(1.0, 1.0).rect # => [0.5403023058681398, 0.8414709848078965]
Complex#rectangular
is an alias for Complex#rect
.
Returns array [self, 0]
.
Returns an unescaped version of self
:
s_orig = "\f\x00\xff\\\"" # => "\f\u0000\xFF\\\"" s_dumped = s_orig.dump # => "\"\\f\\x00\\xFF\\\\\\\"\"" s_undumped = s_dumped.undump # => "\f\u0000\xFF\\\"" s_undumped == s_orig # => true
Related: String#dump
(inverse of String#undump
).
Returns the Encoding
object that represents the encoding of obj.
Returns a copy of self
transcoded as determined by dst_encoding
. By default, raises an exception if self
contains an invalid byte or a character not defined in dst_encoding
; that behavior may be modified by encoding options; see below.
With no arguments:
Uses the same encoding if Encoding.default_internal
is nil
(the default):
Encoding.default_internal # => nil s = "Ruby\x99".force_encoding('Windows-1252') s.encoding # => #<Encoding:Windows-1252> s.bytes # => [82, 117, 98, 121, 153] t = s.encode # => "Ruby\x99" t.encoding # => #<Encoding:Windows-1252> t.bytes # => [82, 117, 98, 121, 226, 132, 162]
Otherwise, uses the encoding Encoding.default_internal
:
Encoding.default_internal = 'UTF-8' t = s.encode # => "Ruby™" t.encoding # => #<Encoding:UTF-8>
With only argument dst_encoding
given, uses that encoding:
s = "Ruby\x99".force_encoding('Windows-1252') s.encoding # => #<Encoding:Windows-1252> t = s.encode('UTF-8') # => "Ruby™" t.encoding # => #<Encoding:UTF-8>
With arguments dst_encoding
and src_encoding
given, interprets self
using src_encoding
, encodes the new string using dst_encoding
:
s = "Ruby\x99" t = s.encode('UTF-8', 'Windows-1252') # => "Ruby™" t.encoding # => #<Encoding:UTF-8>
Optional keyword arguments enc_opts
specify encoding options; see Encoding Options.
Please note that, unless invalid: :replace
option is given, conversion from an encoding enc
to the same encoding enc
(independent of whether enc
is given explicitly or implicitly) is a no-op, i.e. the string is simply copied without any changes, and no exceptions are raised, even if there are invalid bytes.
Like encode
, but applies encoding changes to self
; returns self
.
Checks the compatibility of two objects.
If the objects are both strings they are compatible when they are concatenatable. The encoding of the concatenated string will be returned if they are compatible, nil if they are not.
Encoding.compatible?("\xa1".force_encoding("iso-8859-1"), "b") #=> #<Encoding:ISO-8859-1> Encoding.compatible?( "\xa1".force_encoding("iso-8859-1"), "\xa1\xa1".force_encoding("euc-jp")) #=> nil
If the objects are non-strings their encodings are compatible when they have an encoding and:
Either encoding is US-ASCII compatible
One of the encodings is a 7-bit encoding
Returns true
if self
is a Monday, false
otherwise.
Returns the integer month of the year for self
, in range (1..12):
t = Time.new(2000, 1, 2, 3, 4, 5, 6) # => 2000-01-02 03:04:05 +000006 t.mon # => 1
Returns the integer month of the year for self
, in range (1..12):
t = Time.new(2000, 1, 2, 3, 4, 5, 6) # => 2000-01-02 03:04:05 +000006 t.mon # => 1
Returns true
if self
represents a Monday, false
otherwise:
t = Time.utc(2000, 1, 3) # => 2000-01-03 00:00:00 UTC t.monday? # => true
Related: Time#tuesday?
, Time#wednesday?
, Time#thursday?
.
Returns an File
instance opened console.
If sym
is given, it will be sent to the opened console with args
and the result will be returned instead of the console IO
itself.
You must require ‘io/console’ to use this method.