Results for: "partition"

Shows warning message with the program name

mesg

Message, defaulted to +$!+.

See Kernel#warn.

Shows message with the program name then aborts.

mesg

Message, defaulted to +$!+.

See Kernel#abort.

Puts option summary into to and returns to. Yields each line if a block is given.

to

Output destination, which must have method <<. Defaults to [].

width

Width of left side, defaults to @summary_width.

max

Maximum length allowed for left side, defaults to width - 1.

indent

Indentation, defaults to @summary_indent.

Creates an option from the given parameters params. See Parameters for New Options.

The block, if given, is the handler for the created option. When the option is encountered during command-line parsing, the block is called with the argument given for the option, if any. See Option Handlers.

Parses environment variable env or its uppercase with splitting like a shell.

env defaults to the basename of the program.

Returns the values in self as an array, to use in pattern matching:

Measure = Data.define(:amount, :unit)

distance = Measure[10, 'km']
distance.deconstruct #=> [10, "km"]

# usage
case distance
in n, 'km' # calls #deconstruct underneath
  puts "It is #{n} kilometers away"
else
  puts "Don't know how to handle it"
end
# prints "It is 10 kilometers away"

Or, with checking the class, too:

case distance
in Measure(n, 'km')
  puts "It is #{n} kilometers away"
# ...
end

Returns a shallow copy of self — the instance variables of self are copied, but not the objects they reference.

If the method is supplied any keyword arguments, the copy will be created with the respective field values updated to use the supplied keyword argument values. Note that it is an error to supply a keyword that the Data class does not have as a member.

Point = Data.define(:x, :y)

origin = Point.new(x: 0, y: 0)

up = origin.with(x: 1)
right = origin.with(y: 1)
up_and_right = up.with(y: 1)

p origin       # #<data Point x=0, y=0>
p up           # #<data Point x=1, y=0>
p right        # #<data Point x=0, y=1>
p up_and_right # #<data Point x=1, y=1>

out = origin.with(z: 1) # ArgumentError: unknown keyword: :z
some_point = origin.with(1, 2) # ArgumentError: expected keyword arguments, got positional arguments

Returns the array of captures, which are all matches except m[0]:

m = /(.)(.)(\d+)(\d)/.match("THX1138.")
# => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
m[0]       # => "HX1138"
m.captures # => ["H", "X", "113", "8"]

Related: MatchData.to_a.

Returns the string file path used to create the store:

store.path # => "flat.store"

Exits the current transaction block, committing any changes specified in the transaction block.

Raises an exception if called outside a transaction block.

Exits the current transaction block, discarding any changes specified in the transaction block.

Raises an exception if called outside a transaction block.

Returns the full path name of the temporary file. This will be nil if unlink has been called.

The reason this block was terminated: :break, :redo, :retry, :next, :return, or :noreason.

Returns a clone of this method.

class A
  def foo
    return "bar"
  end
end

m = A.new.method(:foo)
m.call # => "bar"
n = m.clone.call # => "bar"

Returns a clone of this method.

class A
  def foo
    return "bar"
  end
end

m = A.new.method(:foo)
m.call # => "bar"
n = m.clone.call # => "bar"

Checks if the object is shareable by ractors.

Ractor.shareable?(1)            #=> true -- numbers and other immutable basic values are frozen
Ractor.shareable?('foo')        #=> false, unless the string is frozen due to # frozen_string_literal: true
Ractor.shareable?('foo'.freeze) #=> true

See also the “Shareable and unshareable objects” section in the Ractor class docs.

Terminates the currently running thread and schedules another thread to be run.

If this thread is already marked to be killed, ::exit returns the Thread.

If this is the main thread, or the last thread, exit the process.

Give the thread scheduler a hint to pass execution to another thread. A running thread may or may not switch, it depends on OS and processor.

Terminates thr and schedules another thread to be run, returning the terminated Thread. If this is the main thread, or the last thread, exits the process.

Path of the file being run

If object is string-like, parse the string and return the parsed result as a Ruby data structure. Otherwise, generate a JSON text from the Ruby data structure object and return it.

The opts argument is passed through to generate/parse respectively. See generate and parse for their documentation.

Creates a new Pathname object from the given string, path, and returns pathname object.

In order to use this constructor, you must first require the Pathname standard library extension.

require 'pathname'
Pathname("/home/zzak")
#=> #<Pathname:/home/zzak>

See also Pathname::new for more information.

Produces a shallow copy of obj—the instance variables of obj are copied, but not the objects they reference. clone copies the frozen value state of obj, unless the :freeze keyword argument is given with a false or true value. See also the discussion under Object#dup.

class Klass
   attr_accessor :str
end
s1 = Klass.new      #=> #<Klass:0x401b3a38>
s1.str = "Hello"    #=> "Hello"
s2 = s1.clone       #=> #<Klass:0x401b3998 @str="Hello">
s2.str[1,4] = "i"   #=> "i"
s1.inspect          #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
s2.inspect          #=> "#<Klass:0x401b3998 @str=\"Hi\">"

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

Returns an array converted from object.

Tries to convert object to an array using to_ary first and to_a second:

Array([0, 1, 2])        # => [0, 1, 2]
Array({foo: 0, bar: 1}) # => [[:foo, 0], [:bar, 1]]
Array(0..4)             # => [0, 1, 2, 3, 4]

Returns object in an array, [object], if object cannot be converted:

Array(:foo)             # => [:foo]

Exits the process immediately; no exit handlers are called. Returns exit status status to the underlying operating system.

Process.exit!(true)

Values true and false for argument status indicate, respectively, success and failure; The meanings of integer values are system-dependent.

Search took: 8ms  ·  Total Results: 3065