Shortcut for defining multiple delegator methods, but with no provision for using a different name. The following two code samples have the same effect:
def_delegators :@records, :size, :<<, :map def_delegator :@records, :size def_delegator :@records, :<< def_delegator :@records, :map
Define method
as delegator instance method with an optional alias name ali
. Method
calls to ali
will be delegated to accessor.method
. accessor
should be a method name, instance variable name, or constant name. Use the full path to the constant if providing the constant name. Returns the name of the method defined.
class MyQueue CONST = 1 extend Forwardable attr_reader :queue def initialize @queue = [] end def_delegator :@queue, :push, :mypush def_delegator 'MyQueue::CONST', :to_i end q = MyQueue.new q.mypush 42 q.queue #=> [42] q.push 23 #=> NoMethodError q.to_i #=> 1
Called with encoding
when the YAML
stream starts. This method is called once per stream. A stream may contain multiple documents.
See the constants in Psych::Parser
for the possible values of encoding
.
Sends a POST request to the server; forms the response into a Net::HTTPResponse
object.
The request is based on the Net::HTTP::Post
object created from string path
, string data
, and initial headers hash initheader
.
With no block given, returns the response object:
http = Net::HTTP.new(hostname) http.post('/todos', 'xyzzy') # => #<Net::HTTPCreated 201 Created readbody=true>
With a block given, calls the block with the response body and returns the response object:
http.post('/todos', 'xyzzy') do |res| p res end # => #<Net::HTTPCreated 201 Created readbody=true>
Output:
"{\n \"xyzzy\": \"\",\n \"id\": 201\n}"
Sends a POST request to the server; forms the response into a Net::HTTPResponse
object.
The request is based on the Net::HTTP::Post
object created from string path
, string data
, and initial headers hash initheader
.
With no block given, returns the response object:
http = Net::HTTP.new(hostname) http.post('/todos', 'xyzzy') # => #<Net::HTTPCreated 201 Created readbody=true>
With a block given, calls the block with the response body and returns the response object:
http.post('/todos', 'xyzzy') do |res| p res end # => #<Net::HTTPCreated 201 Created readbody=true>
Output:
"{\n \"xyzzy\": \"\",\n \"id\": 201\n}"
Are we doctoring a gem repository?
Return a progress reporter object chosen from the current verbosity.
Returns self
if self
is a String
, or self
converted to a String
if self
is a subclass of String
.
Returns true
if the named file is readable by the real user and group id of this process. See access(3).
Note that some OS-level security features may cause this to return true even though the file is not readable by the real user/group.
If file_name is readable by others, returns an integer representing the file permission bits of file_name. Returns nil
otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2)
.
file_name can be an IO
object.
File.world_readable?("/etc/passwd") #=> 420 m = File.world_readable?("/etc/passwd") sprintf("%o", m) #=> "644"
Returns true
if obj responds to the given method. Private and protected methods are included in the search only if the optional second parameter evaluates to true
.
If the method is not implemented, as Process.fork
on Windows, File.lchmod
on GNU/Linux, etc., false is returned.
If the method is not defined, respond_to_missing?
method is called and the result is returned.
When the method name parameter is given as a string, the string is converted to a symbol.
When this module is prepended in another, Ruby
calls prepend_features
in this module, passing it the receiving module in mod. Ruby’s default implementation is to overlay the constants, methods, and module variables of this module to mod if this module has not already been added to mod or one of its ancestors. See also Module#prepend
.
Removes the definition of the given constant, returning that constant’s previous value. If that constant referred to a module, this will not change that module’s name and can lead to confusion.
Makes a list of existing constants deprecated. Attempt to refer to them will produce a warning.
module HTTP NotFound = Exception.new NOT_FOUND = NotFound # previous version of the library used this name deprecate_constant :NOT_FOUND end HTTP::NOT_FOUND # warning: constant HTTP::NOT_FOUND is deprecated
Returns true
if the given year is a leap year in the proleptic Gregorian calendar, false
otherwise:
Date.gregorian_leap?(2000) # => true Date.gregorian_leap?(2001) # => false
Related: Date.julian_leap?
.