Callback invoked whenever the receiver is included in another module or class. This should be used in preference to Module.append_features
if your code wants to perform some action when a module is included in another.
module A def A.included(mod) puts "#{self} included in #{mod}" end end module Enumerable include A end # => prints "A included in Enumerable"
Returns true
if module is included or prepended in mod or one of mod’s ancestors.
module A end class B include A end class C < B end B.include?(A) #=> true C.include?(A) #=> true A.include?(A) #=> false
Returns a string representing this module or class. For basic classes and modules, this is the name. For singletons, we show information on the thing we’re attached to as well.
Limit the number of significant digits in newly created BigDecimal
numbers to the specified value. Rounding is performed as necessary, as specified by BigDecimal.mode
.
A limit of 0, the default, means no upper limit.
The limit specified by this method takes less priority over any limit specified to instance methods such as ceil, floor, truncate, or round.
Returns a string representation of self.
BigDecimal("1234.5678").inspect #=> "0.12345678e4"
Returns True if the value is finite (not NaN or infinite).
Returns the absolute value of rat
.
(1/2r).abs #=> (1/2) (-1/2r).abs #=> (1/2)
Rational#magnitude
is an alias for Rational#abs
.
Returns the value as a string for inspection.
Rational(2).inspect #=> "(2/1)" Rational(-8, 6).inspect #=> "(-4/3)" Rational('1/2').inspect #=> "(1/2)"
Synonym for $stdin.
Print an argument or list of arguments to the default output stream
cgi = CGI.new cgi.print # default: cgi.print == $DEFAULT_OUTPUT.print
Creates a date object denoting the given ordinal date.
The day of year should be a negative or a positive number (as a relative day from the end of year when negative). It should not be zero.
Date.ordinal(2001) #=> #<Date: 2001-01-01 ...> Date.ordinal(2001,34) #=> #<Date: 2001-02-03 ...> Date.ordinal(2001,-1) #=> #<Date: 2001-12-31 ...>
Returns a hash of parsed elements.
Raise an ArgumentError
when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.
Creates a new Date
object by parsing from a string according to some typical XML Schema formats.
Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
Raise an ArgumentError
when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.
Returns the value as a string for inspection.
Date.new(2001,2,3).inspect #=> "#<Date: 2001-02-03>" DateTime.new(2001,2,3,4,5,6,'-7').inspect #=> "#<DateTime: 2001-02-03T04:05:06-07:00>"
This method is equivalent to strftime(‘%F’).
Creates a DateTime
object denoting the given ordinal date.
DateTime.ordinal(2001,34) #=> #<DateTime: 2001-02-03T00:00:00+00:00 ...> DateTime.ordinal(2001,34,4,5,6,'+7') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...> DateTime.ordinal(2001,-332,-20,-55,-54,'+7') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
Creates a new DateTime
object by parsing from a string according to some typical XML Schema formats.
DateTime.xmlschema('2001-02-03T04:05:06+07:00') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
Raise an ArgumentError
when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.
This method is equivalent to strftime(‘%FT%T%:z’). The optional argument n
is the number of digits for fractional seconds.
DateTime.parse('2001-02-03T04:05:06.123456789+07:00').iso8601(9) #=> "2001-02-03T04:05:06.123456789+07:00"
Parses time
as a dateTime defined by the XML Schema and converts it to a Time
object. The format is a restricted version of the format defined by ISO 8601.
ArgumentError
is raised if time
is not compliant with the format or if the Time
class cannot represent the specified time.
See xmlschema
for more information on this format.
require 'time' Time.xmlschema("2011-10-05T22:26:12-04:00") #=> 2011-10-05 22:26:12-04:00
You must require ‘time’ to use this method.
Returns a string which represents the time as a dateTime defined by XML Schema:
CCYY-MM-DDThh:mm:ssTZD CCYY-MM-DDThh:mm:ss.sssTZD
where TZD is Z or [+-]hh:mm.
If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
fractional_digits
specifies a number of digits to use for fractional seconds. Its default value is 0.
require 'time' t = Time.now t.iso8601 # => "2011-10-05T22:26:12-04:00"
You must require ‘time’ to use this method.
Returns a detailed string representing time. Unlike to_s
, preserves subsecond in the representation for easier debugging.
t = Time.now t.inspect #=> "2012-11-10 18:16:12.261257655 +0100" t.strftime "%Y-%m-%d %H:%M:%S.%N %z" #=> "2012-11-10 18:16:12.261257655 +0100" t.utc.inspect #=> "2012-11-10 17:16:12.261257655 UTC" t.strftime "%Y-%m-%d %H:%M:%S.%N UTC" #=> "2012-11-10 17:16:12.261257655 UTC"
Returns a string representation of self
:
Customer = Struct.new(:name, :address, :zip) # => Customer joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe.inspect # => "#<struct Customer name=\"Joe Smith\", address=\"123 Maple, Anytown NC\", zip=12345>"
Struct#to_s
is an alias for Struct#inspect
.
Tries to set console size. The effect depends on the platform and the running environment.
You must require ‘io/console’ to use this method.
Reads the entire file specified by name as individual lines, and returns those lines in an array. Lines are separated by sep.
If name
starts with a pipe character ("|"
) and the receiver is the IO
class, a subprocess is created in the same way as Kernel#open
, and its output is returned. Consider to use File.readlines
to disable the behavior of subprocess invocation.
a = File.readlines("testfile") a[0] #=> "This is line one\n" b = File.readlines("testfile", chomp: true) b[0] #=> "This is line one" IO.readlines("|ls -a") #=> [".\n", "..\n", ...]
If the last argument is a hash, it’s the keyword argument to open.
The options hash accepts the following keys:
When the optional chomp
keyword argument has a true value, \n
, \r
, and \r\n
will be removed from the end of each line.
See also IO.read
for details about name
and open_args.