Removes the named instance variable from obj, returning that variable’s value. String
arguments are converted to symbols.
class Dummy attr_reader :var def initialize @var = 99 end def remove remove_instance_variable(:@var) end end d = Dummy.new d.var #=> 99 d.remove #=> 99 d.var #=> nil
Defines a singleton method in the receiver. The method parameter can be a Proc
, a Method
or an UnboundMethod
object. If a block is specified, it is used as the method body. If a block or a method has parameters, they’re used as method parameters.
class A class << self def class_name to_s end end end A.define_singleton_method(:who_am_i) do "I am: #{class_name}" end A.who_am_i # ==> "I am: A" guy = "Bob" guy.define_singleton_method(:hello) { "#{self}: Hello there!" } guy.hello #=> "Bob: Hello there!" chris = "Chris" chris.define_singleton_method(:greet) {|greeting| "#{greeting}, I'm Chris!" } chris.greet("Hi") #=> "Hi, I'm Chris!"
Execute the provided block, but preserve the rounding mode
BigDecimal.save_rounding_mode do BigDecimal.mode(BigDecimal::ROUND_MODE, :up) puts BigDecimal.mode(BigDecimal::ROUND_MODE) end
For use with the BigDecimal::ROUND_*
See BigDecimal.mode
Invoked as a callback whenever a singleton method is added to the receiver.
module Chatty def Chatty.singleton_method_added(id) puts "Adding #{id.id2name}" end def self.one() end def two() end def Chatty.three() end end
produces:
Adding singleton_method_added Adding one Adding three
Specifies VI editing mode. See the manual of GNU Readline
for details of VI editing mode.
Raises NotImplementedError
if the using readline library does not support.
Returns true if vi mode is active. Returns false if not.
Raises NotImplementedError
if the using readline library does not support.
Specifies Emacs editing mode. The default is this mode. See the manual of GNU Readline
for details of Emacs editing mode.
Raises NotImplementedError
if the using readline library does not support.
Returns true if emacs mode is active. Returns false if not.
Raises NotImplementedError
if the using readline library does not support.
The current session cache mode.
Sets the SSL
session cache mode. Bitwise-or together the desired SESSION_CACHE_* constants to set. See SSL_CTX_set_session_cache_mode(3) for details.
Returns reference counter of Dispatch interface of WIN32OLE
object. You should not use this method because this method exists only for debugging WIN32OLE
.
Counts objects for each T_IMEMO
type.
This method is only for MRI developers interested in performance and memory usage of Ruby programs.
It returns a hash as:
{:imemo_ifunc=>8, :imemo_svar=>7, :imemo_cref=>509, :imemo_memo=>1, :imemo_throw_data=>1}
If the optional argument, result_hash, is given, it is overwritten and returned. This is intended to avoid probe effect.
The contents of the returned hash is implementation specific and may change in the future.
In this version, keys are symbol objects.
This method is only expected to work with C Ruby.
Add the –prerelease option to the option parser.
Like Enumerable#map
, but chains operation to be lazy-evaluated.
(1..Float::INFINITY).lazy.map {|i| i**2 } #=> #<Enumerator::Lazy: #<Enumerator::Lazy: 1..Infinity>:map> (1..Float::INFINITY).lazy.map {|i| i**2 }.first(3) #=> [1, 4, 9]
Like Enumerable#select
, but chains operation to be lazy-evaluated.
Sends a SELECT command to select a mailbox
so that messages in the mailbox
can be accessed.
After you have selected a mailbox, you may retrieve the number of items in that mailbox from @responses[-1], and the number of recent messages from @responses[-1]. Note that these values can change if new messages arrive during a session; see add_response_handler()
for a way of detecting this event.
A Net::IMAP::NoResponseError
is raised if the mailbox does not exist or is for some reason non-selectable.