Results for: "minmax"

Evaluates a string containing Ruby source code, or the given block, within the context of the receiver (obj). In order to set the context, the variable self is set to obj while the code is executing, giving the code access to obj’s instance variables and private methods.

When instance_eval is given a block, obj is also passed in as the block’s only argument.

When instance_eval is given a String, the optional second and third parameters supply a filename and starting line number that are used when reporting compilation errors.

class KlassWithSecret
  def initialize
    @secret = 99
  end
  private
  def the_secret
    "Ssssh! The secret is #{@secret}."
  end
end
k = KlassWithSecret.new
k.instance_eval { @secret }          #=> 99
k.instance_eval { the_secret }       #=> "Ssssh! The secret is 99."
k.instance_eval {|obj| obj == self } #=> true

Executes the given block within the context of the receiver (obj). In order to set the context, the variable self is set to obj while the code is executing, giving the code access to obj’s instance variables. Arguments are passed as block parameters.

class KlassWithSecret
  def initialize
    @secret = 99
  end
end
k = KlassWithSecret.new
k.instance_exec(5) {|x| @secret+x }   #=> 104

Replaces the entire contents of self with the contents of other_hash; returns self:

h = {foo: 0, bar: 1, baz: 2}
h.replace({bat: 3, bam: 4}) # => {:bat=>3, :bam=>4}

Returns an enumerator which iterates over each line (separated by sep, which defaults to your platform’s newline character) of each file in ARGV. If a block is supplied, each line in turn will be yielded to the block, otherwise an enumerator is returned. The optional limit argument is an Integer specifying the maximum length of each line; longer lines will be split according to this limit.

This method allows you to treat the files supplied on the command line as a single file consisting of the concatenation of each named file. After the last line of the first file has been returned, the first line of the second file is returned. The ARGF.filename and ARGF.lineno methods can be used to determine the filename of the current line and line number of the whole input, respectively.

For example, the following code prints out each line of each named file prefixed with its line number, displaying the filename once per file:

ARGF.each_line do |line|
  puts ARGF.filename if ARGF.file.lineno == 1
  puts "#{ARGF.file.lineno}: #{line}"
end

While the following code prints only the first file’s name at first, and the contents with line number counted through all named files.

ARGF.each_line do |line|
  puts ARGF.filename if ARGF.lineno == 1
  puts "#{ARGF.lineno}: #{line}"
end

Iterates over each codepoint of each file in ARGF.

This method allows you to treat the files supplied on the command line as a single file consisting of the concatenation of each named file. After the last codepoint of the first file has been returned, the first codepoint of the second file is returned. The ARGF.filename method can be used to determine the name of the file in which the current codepoint appears.

If no block is given, an enumerator is returned instead.

Returns the file extension appended to the names of modified files under in-place edit mode. This value can be set using ARGF.inplace_mode= or passing the -i switch to the Ruby binary.

Sets the filename extension for in-place editing mode to the given String. Each file being edited has this value appended to its filename. The modified file is saved under this new name.

For example:

$ ruby argf.rb file.txt

ARGF.inplace_mode = '.bak'
ARGF.each_line do |line|
  print line.sub("foo","bar")
end

Each line of file.txt has the first occurrence of “foo” replaced with “bar”, then the new line is written out to file.txt.bak.

Returns the external encoding for files read from ARGF as an Encoding object. The external encoding is the encoding of the text as stored in a file. Contrast with ARGF.internal_encoding, which is the encoding used to represent this text within Ruby.

To set the external encoding use ARGF.set_encoding.

For example:

ARGF.external_encoding  #=>  #<Encoding:UTF-8>

If single argument is specified, strings read from ARGF are tagged with the encoding specified.

If two encoding names separated by a colon are given, e.g. “ascii:utf-8”, the read string is converted from the first encoding (external encoding) to the second encoding (internal encoding), then tagged with the second encoding.

If two arguments are specified, they must be encoding objects or encoding names. Again, the first specifies the external encoding; the second specifies the internal encoding.

If the external encoding and the internal encoding are specified, the optional Hash argument can be used to adjust the conversion process. The structure of this hash is explained in the String#encode documentation.

For example:

ARGF.set_encoding('ascii')         # Tag the input as US-ASCII text
ARGF.set_encoding(Encoding::UTF_8) # Tag the input as UTF-8 text
ARGF.set_encoding('utf-8','ascii') # Transcode the input from US-ASCII
                                   # to UTF-8.

Returns the String created by generating CSV from ary using the specified options.

Argument ary must be an Array.

Special options:

For other options, see Options for Generating.


Returns the String generated from an Array:

CSV.generate_line(['foo', '0']) # => "foo,0\n"

Raises an exception if ary is not an Array:

# Raises NoMethodError (undefined method `find' for :foo:Symbol)
CSV.generate_line(:foo)

Returns the data created by parsing the first line of string or io using the specified options.

Without Option headers

Without option headers, returns the first row as a new Array.

These examples assume prior execution of:

string = "foo,0\nbar,1\nbaz,2\n"
path = 't.csv'
File.write(path, string)

Parse the first line from a String object:

CSV.parse_line(string) # => ["foo", "0"]

Parse the first line from a File object:

File.open(path) do |file|
  CSV.parse_line(file) # => ["foo", "0"]
end # => ["foo", "0"]

Returns nil if the argument is an empty String:

CSV.parse_line('') # => nil
With Option headers

With {option headers}, returns the first row as a CSV::Row object.

These examples assume prior execution of:

string = "Name,Count\nfoo,0\nbar,1\nbaz,2\n"
path = 't.csv'
File.write(path, string)

Parse the first line from a String object:

CSV.parse_line(string, headers: true) # => #<CSV::Row "Name":"foo" "Count":"0">

Parse the first line from a File object:

File.open(path) do |file|
  CSV.parse_line(file, headers: true)
end # => #<CSV::Row "Name":"foo" "Count":"0">

Raises an exception if the argument is nil:

# Raises ArgumentError (Cannot parse nil as CSV):
CSV.parse_line(nil)

Returns the Regexp used to identify comment lines; used for parsing; see {Option skip_lines}:

CSV.new('').skip_lines # => nil

Returns the value that determines whether illegal input is to be handled; used for parsing; see {Option liberal_parsing}:

CSV.new('').liberal_parsing? # => false
No documentation available

Returns the encoding of the internal IO object.

Returns the list of break points where execution will be stopped.

See DEBUGGER__ for more usage

Serialization support for the object returned by _getobj_.

Reinitializes delegation from a serialized object.

Adds list of ACL entries to this ACL.

Creates a new compiler for ERB. See ERB::Compiler.new for details

Returns a string containing the IP address representation in canonical form.

Returns true if the ipaddr is a link-local address. IPv4 addresses in 169.254.0.0/16 reserved by RFC 3927 and Link-Local IPv6 Unicast Addresses in fe80::/10 reserved by RFC 4291 are considered link-local.

Returns true if the ipaddr is an IPv4-mapped IPv6 address.

Returns a new ipaddr built by converting the native IPv4 address into an IPv4-mapped IPv6 address.

Returns a string for DNS reverse lookup compatible with RFC1886.

Search took: 4ms  ·  Total Results: 1703