This is a discussion on Ruby BuiltIn functions within the Ruby forums, part of the Web Development category; proc proc { block } -> aProc Creates a new procedure object from the given block. Equivalent to Proc.new . aProc = proc { &...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#21
| |||
| |||
| proc proc { block } -> aProc Creates a new procedure object from the given block. Equivalent to Proc.new . aProc = proc { "hello" } aProc.call»"hello" putc putc( anInteger ) -> anInteger Equivalent to $defout.putc( anInteger ). puts puts( [ args ]* ) -> nil Equivalent to $defout.puts( args )
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#22
| |||
| |||
| raise raise( aString ) raise( anException [, aString [ anArray ] ] ) With no arguments, raises the exception in $! or raises a RuntimeError if $! is nil. With a single String argument, raises a RuntimeError with the string as a message. Otherwise, the first parameter should be the name of an Exception class (or an object that returns an Exception when sent exception). The optional second parameter sets the message associated with the exception, and the third parameter is an array of callback information. Exceptions are caught by the rescue clause of begin...end blocks. raise "Failed to create socket" raise ArgumentError, "No parameters", caller
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#23
| |||
| |||
| rand rand( max=0 ) -> aNumber Converts max to an integer using max1 = max.to_i.abs. If the result is zero, returns a pseudorandom floating point number greater than or equal to 0.0 and less than 1.0. Otherwise, returns a pseudorandom integer greater than or equal to zero and less than max1. Kernel::srand may be used to ensure repeatable sequences of random numbers between different runs of the program. srand 1234 » 0 [ rand, rand ] » [0.7408769294, 0.2145348572] [ rand(10), rand(1000) ] » [3, 323] srand 1234 » 1234 [ rand, rand ] » [0.7408769294, 0.2145348572] readline readline( [ aString=$/ ] ) -> aString Equivalent to Kernel::gets , except readline raises EOFError at end of file.
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#24
| |||
| |||
| readlines readlines( [ aString=$/ ] ) -> anArray Returns an array containing the lines returned by calling Kernel.gets(aString) until the end of file. require require( aString ) -> true or false Ruby tries to load the library named aString, returning true if successful. If the filename does not resolve to an absolute path, it will be searched for in the directories listed in $:. If the file has the extension ``.rb'', it is loaded as a source file; if the extension is ``.so'', ``.o'', or ``.dll'',[Or whatever the default shared library extension is on the current platform.] Ruby loads the shared library as a Ruby extension. Otherwise, Ruby tries adding ``.rb'', ``.so'', and so on to the name. The name of the loaded feature is added to the array in $". A feature will not be loaded if it already appears in $". require returns true if the feature was successfully loaded. require "my-library.rb" require "db-driver"
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#25
| |||
| |||
| scan scan( pattern ) -> anArray scan( pattern ) {| | block } -> $_ Equivalent to calling $_.scan. See String#scan on page 373. select select( readArray [, writeArray [ errorArray [ timeout ] ] ] ) -> anArray or nil Performs a low-level select call, which waits for data to become available from input/output devices. The first three parameters are arrays of IO objects or nil. The last is a timeout in seconds, which should be an Integer or a Float. The call waits for data to become available for any of the IO objects in readArray, for buffers to have cleared sufficiently to enable writing to any of the devices in writeArray, or for an error to occur on the devices in errorArray. If one or more of these conditions are met, the call returns a three-element array containing arrays of the IO objects that were ready. Otherwise, if there is no change in status for timeout seconds, the call returns nil. If all parameters are nil, the current thread sleeps forever. select( [$stdin], nil, nil, 1.5 ) » [[#<IO:0x401ba090>], [], []]
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#26
| |||
| |||
| set_trace_func set_trace_func( aProc ) -> aProc set_trace_func( nil ) -> nil Establishes aProc as the handler for tracing, or disables tracing if the parameter is nil. aProc takes up to six parameters: an event name, a filename, a line number, an object id, a binding, and the name of a class. aProc is invoked whenever an event occurs. Events are: c-call (call a C-language routine), c-return (return from a C-language routine), call (call a Ruby method), class (start a class or module definition), end (finish a class or module definition), line (execute code on a new line), raise (raise an exception), and return (return from a Ruby method). Tracing is disabled within the context of aProc
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#27
| |||
| |||
| singleton_method_added singleton_method_added( aFixnum ) -> nil Invoked with a symbol id whenever a singleton method is added to a module or a class. The default implementation in Kernel ignores this, but subclasses may override the method to provide specialized functionality. class Test def Test.singleton_method_added(id) puts "Added #{id.id2name} to Test" end def a() end def Test.b() end end def Test.c() end produces: Added singleton_method_added to Test Added b to Test Added c to Test
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#28
| |||
| |||
| sleep sleep( [ aNumeric ] ) -> aFixnum Suspends the current thread for aNumber seconds (which may be a Float with fractional seconds). Returns the actual number of seconds slept (rounded), which may be less than that asked for if the thread was interrupted by a SIGALRM, or if another thread calls Thread#run . An argument of zero causes sleep to sleep forever. Time.new » Sun Jun 09 00:19:40 CDT 2002 sleep 1.2 » 1 Time.new » Sun Jun 09 00:19:41 CDT 2002 sleep 1.9 » 2 Time.new » Sun Jun 09 00:19:43 CDT 2002
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#29
| |||
| |||
| sprintf sprintf( aFormatString [, arguments ]* ) -> aString Returns the string resulting from applying aFormatString to any additional arguments. Within the format string, any characters other than format sequences are copied to the result. A format sequence consists of a percent sign, followed by optional flags, width, and precision indicators, then terminated with a field type character. The field type controls how the corresponding sprintf argument is to be interpreted, while the flags modify that interpretation.
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#30
| |||
| |||
| srand srand( [ aNumber ] ) -> oldSeed Seeds the pseudorandom number generator to the value of aNumber.to_i.abs. If aNumber is omitted or zero, seeds the generator using a combination of the time, the process id, and a sequence number. (This is also the behavior if Kernel::rand is called without previously calling srand, but without the sequence.) By setting the seed to a known value, scripts can be made deterministic during testing. The previous seed value is returned.
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What Is RUBY? | theseokit | Ruby | 12 | 10-21-2008 11:07 PM |
| PHP vs Ruby | suman | PHP Programming | 2 | 10-02-2008 12:59 AM |
| Is Ruby for Web? | S.Vinothkumar | Ruby | 6 | 11-20-2007 01:25 AM |
| Ruby within .NET? | econwriter5 | Ruby | 0 | 03-07-2007 05:02 PM |
| Ruby IDE | drecko | Ruby | 0 | 02-16-2007 12:11 AM |
Our Partners |