- Subtraction between
Date
classes isRational
Other similar classes of operations are summerized below:
- Subtraction between
Time
classes isFloat
- Subtraction between
DateTime
classes isRational
- Options available in Ruby
-l
: ExecuteString#chop!
at the end of each line-n
: cases Ruby to assume the following loop around your script, which makes it iterate over filename arguments somewhat likesed -n
orawk
-p
: Similar to-n
but output$_
-t
,-f
: Not support-d
: turns on debug mode,$DEBUG
will set true-r filename
: causes Ruby to load the file usingrequire
. It is useful with switches-n
or-p
References: options
Object#methods
- returns a list of the names of public and protected methods of obj. This will include all the methods accessible in obj's ancestors. If the optional parameter is false, it returns an array of obj's public and protected singleton methods, the array will not include methods in modules included in obj
- Syntax:
methods(regular=true) -> array
-
Module#using
cannot be called inside a method. If called, a RuntimeError will occur. -
Proc#yield
is the alias ofProc#call
. So we can use each either
yield args
or
block.call(args)
or
block[args]
or
block.yield(args)
-
If the
::
operator appears at the beginning, constant search is performed from the top level. -
BasicObject#method_missing
is called when a method is not found after following the inheritance chain.BasicObject#method_missing
also follows the inheritance chain. -
%
notation%
is called % notation.
%a/ /
: There is no such notation%/ /
: double quote string%r/ /
: regular expression`%w/ /
: array whose elements are strings- Please refer to the Ruby reference for detailed explanation.
-
Public
Object#instance_variables
: returns an array of instance variable names for the receiver. Note that simply defining an accessor does not create the corresponding instance variable. -
Module#alias_method
- Makes new_name a new copy of the method old_name. This can be used to retain access to methods that are overridden
- Syntax:
alias_method(new_name, old_name) -> symbol
- Note:
alias_method
will create copies of the old_name method. If you modify the old_name method after aliasing. the new_name method will remain unchanged.
- A
variadic function
- In mathematics and in computer programming, a
variadic function
is a function of indefinite arity, i.e., one which accepts a variable number of arguments. Support forvariadic functions
differs widely among programming languages
- Note about
Object#dup
,Marshal.dump
andObject#copy
Object#dup
doeas not copy an object's singleton methods.Marshal.dump
is unable to serialize objects that have singleton methods defined on them- There is no
Object#copy
method
-
Ruby
case..when
case..when
-
Only
date
library has theDate
andDateTime
object, and onlyDateTime
has methodnow
.Time
has method now too, but the result isFloat
, notRational
-
Top-level definition method is private method of
Object
-
The ancestry chain for each of the classes listed in this question is as follows
ArgumentError < StandardError < Exception
ScriptError < Exception
If rescue
is called without a specific error class, it will catch StandardError
and its descendents by default. Most exceptions in core Ruby are descendents of StandardError
, but there are some that are not usually meant to be rescued which exist in other class hierarchies which descend directly from the Exception
base class.
- Casting
a = 1.0 + 1 # Float
a = a + (1/2r) # Float
a = a + (1 + 2i) # Complex