Makes a list of existing constants public.
Returns an UnboundMethod
representing the given instance method in mod.
class Interpreter def do_a() print "there, "; end def do_d() print "Hello "; end def do_e() print "!\n"; end def do_v() print "Dave"; end Dispatcher = { "a" => instance_method(:do_a), "d" => instance_method(:do_d), "e" => instance_method(:do_e), "v" => instance_method(:do_v) } def interpret(string) string.each_char {|b| Dispatcher[b].bind(self).call } end end interpreter = Interpreter.new interpreter.interpret('dave')
produces:
Hello there, Dave!
Deserializes JSON
string by converting numerator value n
, denominator value d
, to a Rational
object.
Returns the fractional part of the day.
DateTime.new(2001,2,3,12).day_fraction #=> (1/2)
Duplicates self and resets its day of calendar reform.
d = Date.new(1582,10,15) d.new_start(Date::JULIAN) #=> #<Date: 1582-10-05 ...>
This method is equivalent to d + n.
This method is equivalent to d - n.
Deserializes JSON
string by converting Julian year y
, month m
, day d
and Day of Calendar Reform sg
to Date
.
Deserializes JSON
string by converting year y
, month m
, day d
, hour H
, minute M
, second S
, offset of
and Day of Calendar Reform sg
to DateTime
.
Returns an array containing the values associated with the given keys.
Returns the struct member values for each selector
as an Array. A selector
may be either an Integer
offset or a Range
of offsets (as in Array#values_at
).
Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe.values_at(0, 2) #=> ["Joe Smith", 12345]
Waits until IO
is readable without blocking and returns self
, or nil
when times out. Returns true
immediately when buffered data is available.
Waits until IO
is writable without blocking and returns self
or nil
when times out.
Returns an array of the values associated with each specified key.
Deserializes JSON
string by constructing new Regexp
object with source s
(Regexp
or String) and options o
serialized by to_json
The first form returns the MatchData
object generated by the last successful pattern match. Equivalent to reading the special global variable $~
(see Special global variables in Regexp
for details).
The second form returns the nth field in this MatchData
object. n can be a string or symbol to reference a named capture.
Note that the last_match
is local to the thread and method scope of the method that did the pattern match.
/c(.)t/ =~ 'cat' #=> 0 Regexp.last_match #=> #<MatchData "cat" 1:"a"> Regexp.last_match(0) #=> "cat" Regexp.last_match(1) #=> "a" Regexp.last_match(2) #=> nil /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ "var = val" Regexp.last_match #=> #<MatchData "var = val" lhs:"var" rhs:"val"> Regexp.last_match(:lhs) #=> "var" Regexp.last_match(:rhs) #=> "val"
Return the path as a String.
to_path
is implemented so Pathname
objects are usable with File.open
, etc.