Results for: "module_function"

Produces a shallow copy of obj—the instance variables of obj are copied, but not the objects they reference. dup copies the tainted state of obj.

This method may have class-specific behavior. If so, that behavior will be documented under the #initialize_copy method of the class.

on dup vs clone

In general, clone and dup may have different semantics in descendant classes. While clone is used to duplicate an object, including its internal state, dup typically uses the class of the descendant object to create the new instance.

When using dup, any modules that the object has been extended with will not be copied.

class Klass
  attr_accessor :str
end

module Foo
  def foo; 'foo'; end
end

s1 = Klass.new #=> #<Klass:0x401b3a38>
s1.extend(Foo) #=> #<Klass:0x401b3a38>
s1.foo #=> "foo"

s2 = s1.clone #=> #<Klass:0x401b3a38>
s2.foo #=> "foo"

s3 = s1.dup #=> #<Klass:0x401b3a38>
s3.foo #=> NoMethodError: undefined method `foo' for #<Klass:0x401b3a38>

Returns a list of the names of public and protected methods of obj. This will include all the methods accessible in obj’s ancestors. If the optional parameter is false, it returns an array of obj<i>‘s public and protected singleton methods, the array will not include methods in modules included in <i>obj.

class Klass
  def klass_method()
  end
end
k = Klass.new
k.methods[0..9]    #=> [:klass_method, :nil?, :===,
                   #    :==~, :!, :eql?
                   #    :hash, :<=>, :class, :singleton_class]
k.methods.length   #=> 56

k.methods(false)   #=> []
def k.singleton_method; end
k.methods(false)   #=> [:singleton_method]

module M123; def m123; end end
k.extend M123
k.methods(false)   #=> [:singleton_method]

Looks up the named method as a receiver in obj, returning a Method object (or raising NameError). The Method object acts as a closure in obj’s object instance, so instance variables and the value of self remain available.

class Demo
  def initialize(n)
    @iv = n
  end
  def hello()
    "Hello, @iv = #{@iv}"
  end
end

k = Demo.new(99)
m = k.method(:hello)
m.call   #=> "Hello, @iv = 99"

l = Demo.new('Fred')
m = l.method("hello")
m.call   #=> "Hello, @iv = Fred"

Multiply by the specified value.

e.g.

c = a.mult(b,n)
c = a * b
digits

If specified and less than the number of significant digits of the result, the result is rounded to that number of digits, according to BigDecimal.mode.

Method used to provide marshalling support.

inf = BigDecimal.new('Infinity')
  #=> #<BigDecimal:1e16fa8,'Infinity',9(9)>
BigDecimal._load(inf._dump)
  #=> #<BigDecimal:1df8dc8,'Infinity',9(9)>

See the Marshal module.

Returns true if int is an odd number.

Returns true if the given year is a leap year of the proleptic Gregorian calendar.

Date.gregorian_leap?(1900)        #=> false
Date.gregorian_leap?(2000)        #=> true

Creates a date object denoting the present day.

Retruns true if the date is before the day of calendar reform.

Date.new(1582,10,15).julian?             #=> false
(Date.new(1582,10,15) - 1).julian?       #=> true

Returns true if the year is a leap year.

Date.new(2000).leap?      #=> true
Date.new(2001).leap?      #=> false

This method is equivalent to new_start(Date::JULIAN).

Returns the number of entries in the database.

Deletes an entry from the database.

Deletes all data from the database.

Returns the number of struct members.

Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.length   #=> 3

This is a deprecated alias for each_codepoint.

Returns an integer representing the numeric file descriptor for ios.

$stdin.fileno    #=> 0
$stdout.fileno   #=> 1

Returns the number of key-value pairs in this database.

Removes the key-value-pair with the specified key from this database and returns the corresponding value. Returns nil if the database is empty.

Removes all the key-value pairs within gdbm.

Alias for Regexp.new

Same as sym.to_s.length.

Returns clean pathname of self with consecutive slashes and useless dots removed. The filesystem is not accessed.

If consider_symlink is true, then a more conservative algorithm is used to avoid breaking symbolic linkages. This may retain more .. entries than absolutely necessary, but without accessing the filesystem, this can’t be avoided.

See Pathname#realpath.

See FileTest.executable?.

See FileTest.file?.

Search took: 6ms  ·  Total Results: 3558