Raises TypeError
, because ENV
is a wrapper for the process-wide environment variables and a clone is useless. Use to_h to get a copy of ENV
data as a hash.
Reads at most maxlen bytes from the ARGF
stream.
If the optional outbuf argument is present, it must reference a String
, which will receive the data. The outbuf will contain only the received data after the method call even if it is not empty at the beginning.
It raises EOFError
on end of ARGF
stream. Since ARGF
stream is a concatenation of multiple files, internally EOF is occur for each file. ARGF.readpartial
returns empty strings for EOFs except the last one and raises EOFError
for the last one.
Returns “ARGF”.
Generate results and print them. (see ERB#result
)
Returns true if the given ipaddr is in the range.
e.g.:
require 'ipaddr' net1 = IPAddr.new("192.168.2.0/24") net2 = IPAddr.new("192.168.2.100") net3 = IPAddr.new("192.168.3.0") net4 = IPAddr.new("192.168.2.0/16") p net1.include?(net2) #=> true p net1.include?(net3) #=> false p net1.include?(net4) #=> false p net4.include?(net1) #=> true
Returns a network byte ordered string form of the IP address.
Returns a new ipaddr built by converting the IPv6 address into a native IPv4 address. If the IP address is not an IPv4-mapped or IPv4-compatible IPv6 address, returns self.
Returns a string containing a human-readable representation of the ipaddr. (“#<IPAddr: family:address/mask>”)
Equivalent to calling add
with severity Logger::UNKNOWN
.
Returns an incremented value of default
according to arg
.
See self.inc
Directs to reject specified class argument.
type
Argument class specifier, any object including Class
.
reject(type)
Creates an option from the given parameters params
. See Parameters for New Options.
The block, if given, is the handler for the created option. When the option is encountered during command-line parsing, the block is called with the argument given for the option, if any. See Option Handlers.
Parses environment variable env
or its uppercase with splitting like a shell.
env
defaults to the basename of the program.
Returns a string representation of self
:
Measure = Data.define(:amount, :unit) distance = Measure[10, 'km'] p distance # uses #inspect underneath #<data Measure amount=10, unit="km"> puts distance # uses #to_s underneath, same representation #<data Measure amount=10, unit="km">
Returns a string representation of self
:
m = /.$/.match("foo") # => #<MatchData "o"> m.inspect # => "#<MatchData \"o\">" m = /(.)(.)(.)/.match("foo") # => #<MatchData "foo" 1:"f" 2:"o" 3:"o"> m.inspect # => "#<MatchData \"foo\" 1:\"f\" 2:\"o\ m = /(.)(.)?(.)/.match("fo") # => #<MatchData "fo" 1:"f" 2:nil 3:"o"> m.inspect # => "#<MatchData \"fo\" 1:\"f\" 2:nil 3:\"o\">"
Related: MatchData#to_s
.
Unlinks (deletes) the file from the filesystem. One should always unlink the file after using it, as is explained in the “Explicit close” good practice section in the Tempfile
overview:
file = Tempfile.new('foo') begin # ...do something with file... ensure file.close file.unlink # deletes the temp file end
On POSIX systems it’s possible to unlink a file before closing it. This practice is explained in detail in the Tempfile
overview (section “Unlink after creation”); please refer there for more information.
However, unlink-before-close may not be supported on non-POSIX operating systems. Microsoft Windows is the most notable case: unlinking a non-closed file will result in an error, which this method will silently ignore. If you want to practice unlink-before-close whenever possible, then you should write code like this:
file = Tempfile.new('foo') file.unlink # On Windows this silently fails. begin # ... do something with file ... ensure file.close! # Closes the file handle. If the file wasn't unlinked # because #unlink failed, then this method will attempt # to do so again. end
The string representation of false
is “false”.
Returns the unique identifier for this proc, along with an indication of where the proc was defined.
The reason this block was terminated: :break, :redo, :retry, :next, :return, or :noreason.
Returns a clone of this method.
class A def foo return "bar" end end m = A.new.method(:foo) m.call # => "bar" n = m.clone.call # => "bar"
Returns a human-readable description of the underlying method.
"cat".method(:count).inspect #=> "#<Method: String#count(*)>" (1..3).method(:map).inspect #=> "#<Method: Range(Enumerable)#map()>"
In the latter case, the method description includes the “owner” of the original method (Enumerable
module, which is included into Range
).
inspect
also provides, when possible, method argument names (call sequence) and source location.
require 'net/http' Net::HTTP.method(:get).inspect #=> "#<Method: Net::HTTP.get(uri_or_host, path=..., port=...) <skip>/lib/ruby/2.7.0/net/http.rb:457>"
...
in argument definition means argument is optional (has some default value).
For methods defined in C (language core and extensions), location and argument names can’t be extracted, and only generic information is provided in form of *
(any number of arguments) or _
(some positional argument).
"cat".method(:count).inspect #=> "#<Method: String#count(*)>" "cat".method(:+).inspect #=> "#<Method: String#+(_)>""
Dissociates meth from its current receiver. The resulting UnboundMethod
can subsequently be bound to a new object of the same class (see UnboundMethod
).