This code is based directly on the Text
gem implementation Returns a value representing the “cost” of transforming str1 into str2
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.
Gets a list of characters which can be used to quote a substring of the line.
Raises NotImplementedError
if the using readline library does not support.
Sets a list of characters that cause a filename to be quoted by the completer when they appear in a completed filename. The default is nil.
Raises NotImplementedError
if the using readline library does not support.
Gets a list of characters that cause a filename to be quoted by the completer when they appear in a completed filename.
Raises NotImplementedError
if the using readline library does not support.
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
Generates URL-encoded form data from given enum
.
This generates application/x-www-form-urlencoded data defined in HTML5 from given an Enumerable
object.
This internally uses URI.encode_www_form_component(str)
.
This method doesn’t convert the encoding of given items, so convert them before calling this method if you want to send data as other than original encoding or mixed encoding data. (Strings which are encoded in an HTML5 ASCII incompatible encoding are converted to UTF-8.)
This method doesn’t handle files. When you send a file, use multipart/form-data.
This refers url.spec.whatwg.org/#concept-urlencoded-serializer
URI.encode_www_form([["q", "ruby"], ["lang", "en"]]) #=> "q=ruby&lang=en" URI.encode_www_form("q" => "ruby", "lang" => "en") #=> "q=ruby&lang=en" URI.encode_www_form("q" => ["ruby", "perl"], "lang" => "en") #=> "q=ruby&q=perl&lang=en" URI.encode_www_form([["q", "ruby"], ["q", "perl"], ["lang", "en"]]) #=> "q=ruby&q=perl&lang=en"
Finds the user’s config file