Generate a Form element with multipart encoding as a String
.
Multipart encoding is used for forms that include file uploads.
action
is the action to perform. enctype
is the encoding type, which defaults to “multipart/form-data”.
Alternatively, the attributes can be specified as a hash.
multipart_form{ "string" } # <FORM METHOD="post" ENCTYPE="multipart/form-data">string</FORM> multipart_form("url") { "string" } # <FORM METHOD="post" ACTION="url" ENCTYPE="multipart/form-data">string</FORM>
A utility method for encoding the String
s as a URL.
require "erb" include ERB::Util puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
Generates
Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
A utility method for encoding the String
s as a URL.
require "erb" include ERB::Util puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
Generates
Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
Returns the value of field 'Content-Length'
as an integer, or nil
if there is no such field; see Content-Length request header:
res = Net::HTTP.get_response(hostname, '/nosuch/1') res.content_length # => 2 res = Net::HTTP.get_response(hostname, '/todos/1') res.content_length # => nil
Sets the value of field 'Content-Length'
to the given numeric; see Content-Length response header:
_uri = uri.dup hostname = _uri.hostname # => "jsonplaceholder.typicode.com" _uri.path = '/posts' # => "/posts" req = Net::HTTP::Post.new(_uri) # => #<Net::HTTP::Post POST> req.body = '{"title": "foo","body": "bar","userId": 1}' req.content_length = req.body.size # => 42 req.content_type = 'application/json' res = Net::HTTP.start(hostname) do |http| http.request(req) end # => #<Net::HTTPCreated 201 Created readbody=true>
Returns a value representing the “cost” of transforming str1 into str2 Vendored version of DidYouMean::Levenshtein.distance from the ruby/did_you_mean gem @ 1.4.0 github.com/ruby/did_you_mean/blob/2ddf39b874808685965dbc47d344cf6c7651807c/lib/did_you_mean/levenshtein.rb#L7-L37
Returns the node id for the given backtrace location.
begin raise rescue => e loc = e.backtrace_locations.first RubyVM::AbstractSyntaxTree.node_id_for_backtrace_location(loc) end # => 0
Returns value specified by the member name of VT_RECORD OLE object. If the member name is not correct, KeyError
exception is raised. If you can’t access member variable of VT_RECORD OLE object directly, use this method.
If COM server in VB.NET ComServer project is the following:
Imports System.Runtime.InteropServices Public Class ComClass Public Structure ComObject Public object_id As Ineger End Structure End Class
and Ruby Object
class has title attribute:
then accessing object_id of ComObject from Ruby is as the following:
srver = WIN32OLE.new('ComServer.ComClass') obj = WIN32OLE_RECORD.new('ComObject', server) # obj.object_id returns Ruby Object#object_id obj.ole_instance_variable_get(:object_id) # => nil
Sets value specified by the member name of VT_RECORD OLE object. If the member name is not correct, KeyError
exception is raised. If you can’t set value of member of VT_RECORD OLE object directly, use this method.
If COM server in VB.NET ComServer project is the following:
Imports System.Runtime.InteropServices Public Class ComClass <MarshalAs(UnmanagedType.BStr)> _ Public title As String Public cost As Integer End Class
then setting value of the ‘title’ member is as following:
srver = WIN32OLE.new('ComServer.ComClass') obj = WIN32OLE_RECORD.new('Book', server) obj.ole_instance_variable_set(:title, "The Ruby Book")
Remove everything in the DependencyList
that matches but doesn’t satisfy items in dependencies
(a hash of gem names to arrays of dependencies).
Returns the value of the given instance variable, or nil if the instance variable is not set. The @
part of the variable name should be included for regular instance variables. Throws a NameError
exception if the supplied symbol is not valid as an instance variable name. String
arguments are converted to symbols.
class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_get(:@a) #=> "cat" fred.instance_variable_get("@b") #=> 99
Sets the instance variable named by symbol to the given object. This may circumvent the encapsulation intended by the author of the class, so it should be used with care. The variable does not have to exist prior to this call. If the instance variable name is passed as a string, that string is converted to a symbol.
class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_set(:@a, 'dog') #=> "dog" fred.instance_variable_set(:@c, 'cat') #=> "cat" fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
Returns true
if the given instance variable is defined in obj. String
arguments are converted to symbols.
class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_defined?(:@a) #=> true fred.instance_variable_defined?("@b") #=> true fred.instance_variable_defined?("@c") #=> false
for compatibility
Returns true when OLE object has OLE method, otherwise returns false.
ie = WIN32OLE.new('InternetExplorer.Application') ie.ole_respond_to?("gohome") => true
Attempts to enter exclusive section. Returns false
if lock fails.
For backward compatibility
Return all reachable objects from ‘obj’.
This method returns all reachable objects from ‘obj’.
If ‘obj’ has two or more references to the same object ‘x’, then returned array only includes one ‘x’ object.
If ‘obj’ is a non-markable (non-heap management) object such as true, false, nil, symbols and Fixnums (and Flonum) then it simply returns nil.
If ‘obj’ has references to an internal object, then it returns instances of ObjectSpace::InternalObjectWrapper
class. This object contains a reference to an internal object and you can check the type of internal object with ‘type’ method.
If ‘obj’ is instance of ObjectSpace::InternalObjectWrapper
class, then this method returns all reachable object from an internal object, which is pointed by ‘obj’.
With this method, you can find memory leaks.
This method is only expected to work except with C Ruby.
Example:
ObjectSpace.reachable_objects_from(['a', 'b', 'c']) #=> [Array, 'a', 'b', 'c'] ObjectSpace.reachable_objects_from(['a', 'a', 'a']) #=> [Array, 'a', 'a', 'a'] # all 'a' strings have different object id ObjectSpace.reachable_objects_from([v = 'a', v, v]) #=> [Array, 'a'] ObjectSpace.reachable_objects_from(1) #=> nil # 1 is not markable (heap managed) object
Load the document contained in filename
. Returns the yaml contained in filename
as a Ruby object, or if the file is empty, it returns the specified fallback
return value, which defaults to false
.
NOTE: This method *should not* be used to parse untrusted documents, such as YAML
documents that are supplied via user input. Instead, please use the safe_load_file
method.
Sets a list of characters which can be used to quote a substring of the line. Completion occurs on the entire substring, and within the substring Readline.completer_word_break_characters
are treated as any other character, unless they also appear within this list.
Raises NotImplementedError
if the using readline library does not support.