Results for: "to_proc"

Returns a hash containing the name and value for each member:

Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
h = joe.to_h
h # => {:name=>"Joe Smith", :address=>"123 Maple, Anytown NC", :zip=>12345}

If a block is given, it is called with each name/value pair; the block should return a 2-element array whose elements will become a key/value pair in the returned hash:

h = joe.to_h{|name, value| [name.upcase, value.to_s.upcase]}
h # => {:NAME=>"JOE SMITH", :ADDRESS=>"123 MAPLE, ANYTOWN NC", :ZIP=>"12345"}

Raises ArgumentError if the block returns an inappropriate value.

Returns a string representation of self:

Customer = Struct.new(:name, :address, :zip) # => Customer
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.inspect # => "#<struct Customer name=\"Joe Smith\", address=\"123 Maple, Anytown NC\", zip=12345>"

Returns a string representation of self (not including the leading colon):

:foo.to_s # => "foo"

Related: Symbol#inspect, Symbol#name.

Return the path as a String.

to_path is implemented so Pathname objects are usable with File.open, etc.

returns the socket address as packed struct sockaddr string.

Addrinfo.tcp("localhost", 80).to_sockaddr
#=> "\x02\x00\x00P\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"

For an instance of Hash, returns self.

For a subclass of Hash, returns a new Hash containing the content of self.

When a block is given, returns a new Hash object whose content is based on the block; the block should return a 2-element Array object specifying the key-value pair to be included in the returned Array:

h = {foo: 0, bar: 1, baz: 2}
h1 = h.to_h {|key, value| [value, key] }
h1 # => {0=>:foo, 1=>:bar, 2=>:baz}

Returns a new Array of 2-element Array objects; each nested Array contains a key-value pair from self:

h = {foo: 0, bar: 1, baz: 2}
h.to_a # => [[:foo, 0], [:bar, 1], [:baz, 2]]

Returns a new String containing the hash entries:

h = {foo: 0, bar: 1, baz: 2}
h.inspect # => "{:foo=>0, :bar=>1, :baz=>2}"

Returns the contents of ENV as an Array of 2-element Arrays, each of which is a name/value pair:

ENV.replace('foo' => '0', 'bar' => '1')
ENV.to_a # => [["bar", "1"], ["foo", "0"]]

Returns String ‘ENV’:

ENV.to_s # => "ENV"

With no block, returns a Hash containing all name/value pairs from ENV:

ENV.replace('foo' => '0', 'bar' => '1')
ENV.to_h # => {"bar"=>"1", "foo"=>"0"}

With a block, returns a Hash whose items are determined by the block. Each name/value pair in ENV is yielded to the block. The block must return a 2-element Array (name/value pair) that is added to the return Hash as a key and value:

ENV.to_h { |name, value| [name.to_sym, value.to_i] } # => {:bar=>1, :foo=>0}

Raises an exception if the block does not return an Array:

ENV.to_h { |name, value| name } # Raises TypeError (wrong element type String (expected array))

Raises an exception if the block returns an Array of the wrong size:

ENV.to_h { |name, value| [name] } # Raises ArgumentError (element has wrong array length (expected 2, was 1))

Returns “ARGF”.

Returns an integer representing the numeric file descriptor for the current file. Raises an ArgumentError if there isn’t a current file.

ARGF.fileno    #=> 3

Reads each file in ARGF in its entirety, returning an Array containing lines from the files. Lines are assumed to be separated by sep.

lines = ARGF.readlines
lines[0]                #=> "This is line one\n"

See IO.readlines for a full description of all options.

No documentation available

Returns the integer representation of the ipaddr.

Returns a string containing the IP address representation.

No documentation available

Returns option summary list.

Returns Hash representation of the data object.

Measure = Data.define(:amount, :unit)
distance = Measure[10, 'km']

distance.to_h
#=> {:amount=>10, :unit=>"km"}

Like Enumerable#to_h, if the block is provided, it is expected to produce key-value pairs to construct a hash:

distance.to_h { |name, val| [name.to_s, val.to_s] }
#=> {"amount"=>"10", "unit"=>"km"}

Note that there is a useful symmetry between to_h and initialize:

distance2 = Measure.new(**distance.to_h)
#=> #<data Measure amount=10, unit="km">
distance2 == distance
#=> true

Returns a string representation of self:

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

distance = Measure[10, 'km']

p distance  # uses #inspect underneath
#<data Measure amount=10, unit="km">

puts distance  # uses #to_s underneath, same representation
#<data Measure amount=10, unit="km">

Returns the array of matches:

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

Related: MatchData#captures.

Returns the matched string:

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

m = /(?<foo>.)(.)(?<bar>.+)/.match("hoge")
# => #<MatchData "hoge" foo:"h" bar:"ge">
m.to_s # => "hoge"

Related: MatchData.inspect.

Returns string 'true':

true.to_s # => "true"

TrueClass#inspect is an alias for TrueClass#to_s.

The string representation of false is “false”.

Search took: 4ms  ·  Total Results: 1894