Method: Timezone.fetch

Defined in:
lib/timezone.rb

.fetch(name, default = :__block) {|name| ... } ⇒ Timezone::Zone, Object

Fetch a timezone by name.

Parameters:

  • name (String)

    the timezone name

  • default (defaults to: :__block)

    an object to return if timezone is not found

Yields:

  • the block to run if the timezone is not found

Yield Parameters:

  • name (String)

    the timezone name if the timezone is not found

Returns:

  • (Timezone::Zone)

    if the timezone is found

  • (Object)

    if the timezone is not found and a default value or block has been provided

Raises:

[View source]

42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/timezone.rb', line 42

def self.fetch(name, default = :__block, &block)
  return ::Timezone::Zone.new(name) if Loader.valid?(name)

  if block_given? && default != :__block
    warn('warning: block supersedes default value argument')
  end

  return block.call(name) if block_given?
  return default unless default == :__block

  raise ::Timezone::Error::InvalidZone
end