Results for: "partition"

Returns an array of the names of class variables in mod. This includes the names of class variables in any included modules, unless the inherit parameter is set to false.

class One
  @@var1 = 1
end
class Two < One
  @@var2 = 2
end
One.class_variables          #=> [:@@var1]
Two.class_variables          #=> [:@@var2, :@@var1]
Two.class_variables(false)   #=> [:@@var2]

Makes a list of existing constants public.

Makes a list of existing constants private.

Makes a list of existing constants deprecated. Attempt to refer to them will produce a warning.

module HTTP
  NotFound = Exception.new
  NOT_FOUND = NotFound # previous version of the library used this name

  deprecate_constant :NOT_FOUND
end

HTTP::NOT_FOUND
# warning: constant HTTP::NOT_FOUND is deprecated

Returns true if mod is a singleton class or false if it is an ordinary class or module.

class C
end
C.singleton_class?                  #=> false
C.singleton_class.singleton_class?  #=> true

Return the accept character set for all new CGI instances.

Set the accept character set for all new CGI instances.

Equivalent to >> with argument n.

Equivalent to << with argument n.

Equivalent to >> with argument n * 12.

Equivalent to << with argument n * 12.

Returns a hash of the name/value pairs, to use in pattern matching. Possible keys are: :year, :month, :day, :wday, :yday.

Possible usages:

d = Date.new(2022, 10, 5)

if d in wday: 3, day: ..7  # uses deconstruct_keys underneath
  puts "first Wednesday of the month"
end
#=> prints "first Wednesday of the month"

case d
in year: ...2022
  puts "too old"
in month: ..9
  puts "quarter 1-3"
in wday: 1..5, month:
  puts "working day in month #{month}"
end
#=> prints "working day in month 10"

Note that deconstruction by pattern can also be combined with class check:

if d in Date(wday: 3, day: ..7)
  puts "first Wednesday of the month"
end

See as_json.

Methods Date#as_json and Date.json_create may be used to serialize and deserialize a Date object; see Marshal.

Method Date#as_json serializes self, returning a 2-element hash representing self:

require 'json/add/date'
x = Date.today.as_json
# => {"json_class"=>"Date", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}

Method JSON.create deserializes such a hash, returning a Date object:

Date.json_create(x)
# => #<Date: 2023-11-21 ((2460270j,0s,0n),+0s,2299161j)>

Returns a JSON string representing self:

require 'json/add/date'
puts Date.today.to_json

Output:

{"json_class":"Date","y":2023,"m":11,"d":21,"sg":2299161.0}

Returns a hash of the name/value pairs, to use in pattern matching. Possible keys are: :year, :month, :day, :wday, :yday, :hour, :min, :sec, :sec_fraction, :zone.

Possible usages:

dt = DateTime.new(2022, 10, 5, 13, 30)

if d in wday: 1..5, hour: 10..18  # uses deconstruct_keys underneath
  puts "Working time"
end
#=> prints "Working time"

case dt
in year: ...2022
  puts "too old"
in month: ..9
  puts "quarter 1-3"
in wday: 1..5, month:
  puts "working day in month #{month}"
end
#=> prints "working day in month 10"

Note that deconstruction by pattern can also be combined with class check:

if d in DateTime(wday: 1..5, hour: 10..18, day: ..7)
  puts "Working time, first week of the month"
end

See as_json.

Methods DateTime#as_json and DateTime.json_create may be used to serialize and deserialize a DateTime object; see Marshal.

Method DateTime#as_json serializes self, returning a 2-element hash representing self:

require 'json/add/datetime'
x = DateTime.now.as_json
# => {"json_class"=>"DateTime", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}

Method JSON.create deserializes such a hash, returning a DateTime object:

DateTime.json_create(x) # BUG? Raises Date::Error "invalid date"

Returns a JSON string representing self:

require 'json/add/datetime'
puts DateTime.now.to_json

Output:

{"json_class":"DateTime","y":2023,"m":11,"d":21,"sg":2299161.0}

See as_json.

Methods Time#as_json and Time.json_create may be used to serialize and deserialize a Time object; see Marshal.

Method Time#as_json serializes self, returning a 2-element hash representing self:

require 'json/add/time'
x = Time.now.as_json
# => {"json_class"=>"Time", "s"=>1700931656, "n"=>472846644}

Method JSON.create deserializes such a hash, returning a Time object:

Time.json_create(x)
# => 2023-11-25 11:00:56.472846644 -0600

Returns a JSON string representing self:

require 'json/add/time'
puts Time.now.to_json

Output:

{"json_class":"Time","s":1700931678,"n":980650786}

Return the number of seconds the specified time zone differs from UTC.

Numeric time zones that include minutes, such as -10:00 or +1330 will work, as will simpler hour-only time zones like -10 or +13.

Textual time zones listed in ZoneOffset are also supported.

If the time zone does not match any of the above, zone_offset will check if the local time zone (both with and without potential Daylight Saving Time changes being in effect) matches zone. Specifying a value for year will change the year used to find the local time zone.

If zone_offset is unable to determine the offset, nil will be returned.

require 'time'

Time.zone_offset("EST") #=> -18000

You must require ‘time’ to use this method.

Returns a hash of the name/value pairs, to use in pattern matching. Possible keys are: :year, :month, :day, :yday, :wday, :hour, :min, :sec, :subsec, :dst, :zone.

Possible usages:

t = Time.utc(2022, 10, 5, 21, 25, 30)

if t in wday: 3, day: ..7  # uses deconstruct_keys underneath
  puts "first Wednesday of the month"
end
#=> prints "first Wednesday of the month"

case t
in year: ...2022
  puts "too old"
in month: ..9
  puts "quarter 1-3"
in wday: 1..5, month:
  puts "working day in month #{month}"
end
#=> prints "working day in month 10"

Note that deconstruction by pattern can also be combined with class check:

if t in Time(wday: 3, day: ..7)
  puts "first Wednesday of the month"
end

Returns a data represents the current console mode.

You must require ‘io/console’ to use this method.

Search took: 5ms  ·  Total Results: 4702