* proc.c (proc_dup): should copy is_lambda attribute as well.
[ruby-talk:296244] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c8ac4a209b
commit
3730710d79
@ -1,3 +1,8 @@
|
|||||||
|
Sun Mar 30 23:16:49 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* proc.c (proc_dup): should copy is_lambda attribute as well.
|
||||||
|
[ruby-talk:296244]
|
||||||
|
|
||||||
Sun Mar 30 15:33:29 2008 Tanaka Akira <akr@fsij.org>
|
Sun Mar 30 15:33:29 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* io.c: IO.copy_stream implemented. [ruby-dev:33843]
|
* io.c: IO.copy_stream implemented. [ruby-dev:33843]
|
||||||
|
45
complex.c
45
complex.c
@ -84,22 +84,6 @@ f_add(VALUE x, VALUE y)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static VALUE
|
|
||||||
f_cmp(VALUE x, VALUE y)
|
|
||||||
{
|
|
||||||
VALUE r;
|
|
||||||
if (FIXNUM_P(x) && FIXNUM_P(y)) {
|
|
||||||
long c = FIX2LONG(x) - FIX2LONG(y);
|
|
||||||
if (c > 0)
|
|
||||||
c = 1;
|
|
||||||
else if (c < 0)
|
|
||||||
c = -1;
|
|
||||||
r = INT2FIX(c);
|
|
||||||
} else
|
|
||||||
r = rb_funcall(x, id_cmp, 1, y);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static VALUE
|
inline static VALUE
|
||||||
f_div(VALUE x, VALUE y)
|
f_div(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
@ -200,6 +184,22 @@ fun1(to_r)
|
|||||||
fun1(to_s)
|
fun1(to_s)
|
||||||
fun1(truncate)
|
fun1(truncate)
|
||||||
|
|
||||||
|
inline static VALUE
|
||||||
|
f_cmp(VALUE x, VALUE y)
|
||||||
|
{
|
||||||
|
VALUE r;
|
||||||
|
if (FIXNUM_P(x) && FIXNUM_P(y)) {
|
||||||
|
long c = FIX2LONG(x) - FIX2LONG(y);
|
||||||
|
if (c > 0)
|
||||||
|
c = 1;
|
||||||
|
else if (c < 0)
|
||||||
|
c = -1;
|
||||||
|
r = INT2FIX(c);
|
||||||
|
} else
|
||||||
|
r = rb_funcall(x, id_cmp, 1, y);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
fun2(coerce)
|
fun2(coerce)
|
||||||
fun2(divmod)
|
fun2(divmod)
|
||||||
|
|
||||||
@ -1016,13 +1016,22 @@ nucomp_inexact_p(VALUE self)
|
|||||||
return f_boolcast(!nucomp_exact_p(self));
|
return f_boolcast(!nucomp_exact_p(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern VALUE rb_lcm(VALUE x, VALUE y);
|
extern VALUE rb_gcd(VALUE x, VALUE y);
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
f_lcm(VALUE x, VALUE y)
|
||||||
|
{
|
||||||
|
if (f_zero_p(x) || f_zero_p(y))
|
||||||
|
return ZERO;
|
||||||
|
else
|
||||||
|
return f_abs(f_mul(f_div(x, rb_gcd(x, y)), y));
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
nucomp_denominator(VALUE self)
|
nucomp_denominator(VALUE self)
|
||||||
{
|
{
|
||||||
get_dat1(self);
|
get_dat1(self);
|
||||||
return rb_lcm(f_denominator(dat->real), f_denominator(dat->image));
|
return f_lcm(f_denominator(dat->real), f_denominator(dat->image));
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -11,7 +11,7 @@ t1 = TkText.new(:height=>5).pack
|
|||||||
t2 = TkText.new(:height=>5).pack
|
t2 = TkText.new(:height=>5).pack
|
||||||
t3 = TkText.new(:height=>5).pack
|
t3 = TkText.new(:height=>5).pack
|
||||||
|
|
||||||
src_str = IO.readlines(File.join(File.dirname(__FILE__),'iso2022-kr.txt')).join
|
src_str = IO.readlines('iso2022-kr.txt').join
|
||||||
|
|
||||||
t1.insert('end',
|
t1.insert('end',
|
||||||
"use neither Tk::EncodedString class nor Tk.encoding= method\n\n")
|
"use neither Tk::EncodedString class nor Tk.encoding= method\n\n")
|
||||||
@ -23,8 +23,7 @@ t2.insert('end',
|
|||||||
t2.insert('end', enc_str)
|
t2.insert('end', enc_str)
|
||||||
|
|
||||||
Tk.encoding = 'iso2022-kr'
|
Tk.encoding = 'iso2022-kr'
|
||||||
t3.insert('end', "use Tk.encoding = 'iso2022-kr' (Tk.force_default_encoding? == #{Tk.force_default_encoding?})\n\n")
|
t3.insert('end', "use Tk.encoding = 'iso2022-kr'\n\n")
|
||||||
|
|
||||||
t3.insert('end', src_str)
|
t3.insert('end', src_str)
|
||||||
|
|
||||||
Tk.mainloop
|
Tk.mainloop
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
|
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
|
||||||
#
|
#
|
||||||
release = '2008/03/08'
|
release = '2006/11/06'
|
||||||
|
|
||||||
require 'tk'
|
require 'tk'
|
||||||
begin
|
begin
|
||||||
@ -15,32 +15,10 @@ end
|
|||||||
|
|
||||||
require 'irb'
|
require 'irb'
|
||||||
|
|
||||||
if TkCore::WITH_ENCODING
|
|
||||||
else
|
|
||||||
# $KCODE setup
|
|
||||||
case Tk.encoding
|
|
||||||
when 'shiftjis', 'cp932'
|
|
||||||
$KCODE='SJIS'
|
|
||||||
when 'euc-jp'
|
|
||||||
$KCODE='EUC'
|
|
||||||
when 'utf-8', 'unicode'
|
|
||||||
$KCODE='UTF8'
|
|
||||||
else
|
|
||||||
# unknown
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# console setup
|
# console setup
|
||||||
top = TkToplevel.new(:title=>'IRB console')
|
top = TkToplevel.new(:title=>'IRB console')
|
||||||
top.protocol(:WM_DELETE_WINDOW){ Tk.exit }
|
top.protocol(:WM_DELETE_WINDOW){ Tk.exit }
|
||||||
|
|
||||||
case (Tk.windowingsystem)
|
|
||||||
when 'win32'
|
|
||||||
fnt = ['MS Gothic', '-12']
|
|
||||||
else
|
|
||||||
fnt = ['courier', '-12']
|
|
||||||
end
|
|
||||||
|
|
||||||
console = TkTextIO.new(top, :mode=>:console,
|
console = TkTextIO.new(top, :mode=>:console,
|
||||||
:width=>80).pack(:side=>:left,
|
:width=>80).pack(:side=>:left,
|
||||||
:expand=>true, :fill=>:both)
|
:expand=>true, :fill=>:both)
|
||||||
|
@ -17,17 +17,8 @@ TkLabel.new(f2, :text=>'use TkRTTimer class').pack
|
|||||||
label2 = TkLabel.new(:parent=>f2, :relief=>:raised,
|
label2 = TkLabel.new(:parent=>f2, :relief=>:raised,
|
||||||
:width=>10).pack(:fill=>:both)
|
:width=>10).pack(:fill=>:both)
|
||||||
|
|
||||||
TkLabel.new(:padx=>10, :pady=>5, :justify=>'left', :text=><<EOT).pack
|
TkLabel.new(:text=>'Interval setting of each timer is 10 ms.',
|
||||||
Interval setting of each timer object is 10 ms.
|
:padx=>10, :pady=>5).pack
|
||||||
Each timer object counts up the value on each callback
|
|
||||||
(the value is not the clock data).
|
|
||||||
The count of the TkTimer object is delayed by execution
|
|
||||||
time of callbacks and inaccuracy of interval.
|
|
||||||
On the other hand, the count of the TkRTTimer object is
|
|
||||||
not delayed. Its callback interval is not accurate too.
|
|
||||||
But it can compute error correction about the time when
|
|
||||||
a callback should start.
|
|
||||||
EOT
|
|
||||||
|
|
||||||
# define the procedure repeated by the TkTimer object
|
# define the procedure repeated by the TkTimer object
|
||||||
tick = proc{|aobj| #<== TkTimer object
|
tick = proc{|aobj| #<== TkTimer object
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
/************************************************
|
|
||||||
|
|
||||||
stubs.c - Tcl/Tk stubs support
|
|
||||||
|
|
||||||
************************************************/
|
|
||||||
|
|
||||||
#include "ruby.h"
|
|
||||||
#include "stubs.h"
|
#include "stubs.h"
|
||||||
|
#include "ruby/ruby.h"
|
||||||
#include <tcl.h>
|
#include <tcl.h>
|
||||||
#include <tk.h>
|
#include <tk.h>
|
||||||
|
|
||||||
@ -92,12 +86,7 @@ static DL_HANDLE tcl_dll = (DL_HANDLE)0;
|
|||||||
static DL_HANDLE tk_dll = (DL_HANDLE)0;
|
static DL_HANDLE tk_dll = (DL_HANDLE)0;
|
||||||
|
|
||||||
int
|
int
|
||||||
#ifdef RUBY_VM
|
|
||||||
ruby_open_tcl_dll(char *appname)
|
ruby_open_tcl_dll(char *appname)
|
||||||
#else
|
|
||||||
ruby_open_tcl_dll(appname)
|
|
||||||
char *appname;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
void (*p_Tcl_FindExecutable)(const char *);
|
void (*p_Tcl_FindExecutable)(const char *);
|
||||||
int n;
|
int n;
|
||||||
@ -179,12 +168,7 @@ ruby_open_tk_dll()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
#ifdef RUBY_VM
|
|
||||||
ruby_open_tcltk_dll(char *appname)
|
ruby_open_tcltk_dll(char *appname)
|
||||||
#else
|
|
||||||
ruby_open_tcltk_dll(appname)
|
|
||||||
char *appname;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
return( ruby_open_tcl_dll(appname) || ruby_open_tk_dll() );
|
return( ruby_open_tcl_dll(appname) || ruby_open_tk_dll() );
|
||||||
}
|
}
|
||||||
@ -203,12 +187,7 @@ tk_stubs_init_p()
|
|||||||
|
|
||||||
|
|
||||||
Tcl_Interp *
|
Tcl_Interp *
|
||||||
#ifdef RUBY_VM
|
|
||||||
ruby_tcl_create_ip_and_stubs_init(int *st)
|
ruby_tcl_create_ip_and_stubs_init(int *st)
|
||||||
#else
|
|
||||||
ruby_tcl_create_ip_and_stubs_init(st)
|
|
||||||
int *st;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
Tcl_Interp *tcl_ip;
|
Tcl_Interp *tcl_ip;
|
||||||
|
|
||||||
@ -290,12 +269,7 @@ ruby_tcl_stubs_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
#ifdef RUBY_VM
|
|
||||||
ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
|
ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
|
||||||
#else
|
|
||||||
ruby_tk_stubs_init(tcl_ip)
|
|
||||||
Tcl_Interp *tcl_ip;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
Tcl_ResetResult(tcl_ip);
|
Tcl_ResetResult(tcl_ip);
|
||||||
|
|
||||||
@ -330,12 +304,7 @@ ruby_tk_stubs_init(tcl_ip)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
#ifdef RUBY_VM
|
|
||||||
ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
|
ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
|
||||||
#else
|
|
||||||
ruby_tk_stubs_safeinit(tcl_ip)
|
|
||||||
Tcl_Interp *tcl_ip;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
Tcl_ResetResult(tcl_ip);
|
Tcl_ResetResult(tcl_ip);
|
||||||
|
|
||||||
@ -421,12 +390,7 @@ static int open_tcl_dll = 0;
|
|||||||
static int call_tk_stubs_init = 0;
|
static int call_tk_stubs_init = 0;
|
||||||
|
|
||||||
int
|
int
|
||||||
#ifdef RUBY_VM
|
|
||||||
ruby_open_tcl_dll(char *appname)
|
ruby_open_tcl_dll(char *appname)
|
||||||
#else
|
|
||||||
ruby_open_tcl_dll(appname)
|
|
||||||
char *appname;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
if (appname) {
|
if (appname) {
|
||||||
Tcl_FindExecutable(appname);
|
Tcl_FindExecutable(appname);
|
||||||
@ -438,8 +402,7 @@ ruby_open_tcl_dll(appname)
|
|||||||
return TCLTK_STUBS_OK;
|
return TCLTK_STUBS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int ruby_open_tk_dll()
|
||||||
ruby_open_tk_dll()
|
|
||||||
{
|
{
|
||||||
if (!open_tcl_dll) {
|
if (!open_tcl_dll) {
|
||||||
/* ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */
|
/* ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */
|
||||||
@ -449,13 +412,7 @@ ruby_open_tk_dll()
|
|||||||
return TCLTK_STUBS_OK;
|
return TCLTK_STUBS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int ruby_open_tcltk_dll(char *appname)
|
||||||
#ifdef RUBY_VM
|
|
||||||
ruby_open_tcltk_dll(char *appname)
|
|
||||||
#else
|
|
||||||
ruby_open_tcltk_dll(appname)
|
|
||||||
char *appname;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
return( ruby_open_tcl_dll(appname) || ruby_open_tk_dll() );
|
return( ruby_open_tcl_dll(appname) || ruby_open_tk_dll() );
|
||||||
}
|
}
|
||||||
@ -473,12 +430,7 @@ tk_stubs_init_p()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tcl_Interp *
|
Tcl_Interp *
|
||||||
#ifdef RUBY_VM
|
|
||||||
ruby_tcl_create_ip_and_stubs_init(int *st)
|
ruby_tcl_create_ip_and_stubs_init(int *st)
|
||||||
#else
|
|
||||||
ruby_tcl_create_ip_and_stubs_init(st)
|
|
||||||
int *st;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
Tcl_Interp *tcl_ip;
|
Tcl_Interp *tcl_ip;
|
||||||
|
|
||||||
@ -506,12 +458,7 @@ ruby_tcl_stubs_init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
#ifdef RUBY_VM
|
|
||||||
ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
|
ruby_tk_stubs_init(Tcl_Interp *tcl_ip)
|
||||||
#else
|
|
||||||
ruby_tk_stubs_init(tcl_ip)
|
|
||||||
Tcl_Interp *tcl_ip;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
if (Tk_Init(tcl_ip) == TCL_ERROR)
|
if (Tk_Init(tcl_ip) == TCL_ERROR)
|
||||||
return FAIL_Tk_Init;
|
return FAIL_Tk_Init;
|
||||||
@ -527,12 +474,7 @@ ruby_tk_stubs_init(tcl_ip)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
#ifdef RUBY_VM
|
|
||||||
ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
|
ruby_tk_stubs_safeinit(Tcl_Interp *tcl_ip)
|
||||||
#else
|
|
||||||
ruby_tk_stubs_safeinit(tcl_ip)
|
|
||||||
Tcl_Interp *tcl_ip;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
#if TCL_MAJOR_VERSION >= 8
|
#if TCL_MAJOR_VERSION >= 8
|
||||||
if (Tk_SafeInit(tcl_ip) == TCL_ERROR)
|
if (Tk_SafeInit(tcl_ip) == TCL_ERROR)
|
||||||
|
179
io.c
179
io.c
@ -2228,12 +2228,64 @@ rb_io_each_byte(VALUE io)
|
|||||||
return io;
|
return io;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* str.lines(sep=$/) => anEnumerator
|
||||||
|
* str.lines(limit) => anEnumerator
|
||||||
|
* str.lines(sep, limit) => anEnumerator
|
||||||
|
*
|
||||||
|
* Returns an enumerator that gives each line in the string.
|
||||||
|
*
|
||||||
|
* "foo\nbar\n".lines.to_a #=> ["foo\n", "bar\n"]
|
||||||
|
* "foo\nb ar".lines.sort #=> ["b ar", "foo\n"]
|
||||||
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
io_getc(rb_io_t *fptr, rb_encoding *enc)
|
rb_io_lines(int argc, VALUE *argv, VALUE str)
|
||||||
{
|
{
|
||||||
|
return rb_enumeratorize(str, ID2SYM(rb_intern("each_line")), argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* str.bytes => anEnumerator
|
||||||
|
*
|
||||||
|
* Returns an enumerator that gives each byte in the string.
|
||||||
|
*
|
||||||
|
* "hello".bytes.to_a #=> [104, 101, 108, 108, 111]
|
||||||
|
*/
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
rb_io_bytes(VALUE str)
|
||||||
|
{
|
||||||
|
return rb_enumeratorize(str, ID2SYM(rb_intern("each_byte")), 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* ios.getc => fixnum or nil
|
||||||
|
*
|
||||||
|
* Reads a one-character string from <em>ios</em>. Returns
|
||||||
|
* <code>nil</code> if called at end of file.
|
||||||
|
*
|
||||||
|
* f = File.new("testfile")
|
||||||
|
* f.getc #=> "8"
|
||||||
|
* f.getc #=> "1"
|
||||||
|
*/
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
rb_io_getc(VALUE io)
|
||||||
|
{
|
||||||
|
rb_io_t *fptr;
|
||||||
int r, n;
|
int r, n;
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
rb_encoding *enc;
|
||||||
|
|
||||||
|
GetOpenFile(io, fptr);
|
||||||
|
rb_io_check_readable(fptr);
|
||||||
|
|
||||||
|
enc = io_input_encoding(fptr);
|
||||||
|
READ_CHECK(fptr);
|
||||||
if (io_fillbuf(fptr) < 0) {
|
if (io_fillbuf(fptr) < 0) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
@ -2266,117 +2318,6 @@ io_getc(rb_io_t *fptr, rb_encoding *enc)
|
|||||||
return io_enc_str(str, fptr);
|
return io_enc_str(str, fptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* call-seq:
|
|
||||||
* ios.each_char {|c| block } => ios
|
|
||||||
*
|
|
||||||
* Calls the given block once for each character in <em>ios</em>,
|
|
||||||
* passing the character as an argument. The stream must be opened for
|
|
||||||
* reading or an <code>IOError</code> will be raised.
|
|
||||||
*
|
|
||||||
* f = File.new("testfile")
|
|
||||||
* f.each_char {|c| print c, ' ' } #=> #<File:testfile>
|
|
||||||
*/
|
|
||||||
|
|
||||||
static VALUE
|
|
||||||
rb_io_each_char(VALUE io)
|
|
||||||
{
|
|
||||||
rb_io_t *fptr;
|
|
||||||
rb_encoding *enc;
|
|
||||||
VALUE c;
|
|
||||||
|
|
||||||
RETURN_ENUMERATOR(io, 0, 0);
|
|
||||||
GetOpenFile(io, fptr);
|
|
||||||
rb_io_check_readable(fptr);
|
|
||||||
|
|
||||||
enc = io_input_encoding(fptr);
|
|
||||||
READ_CHECK(fptr);
|
|
||||||
while (!NIL_P(c = io_getc(fptr, enc))) {
|
|
||||||
rb_yield(c);
|
|
||||||
}
|
|
||||||
return io;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* call-seq:
|
|
||||||
* str.lines(sep=$/) => anEnumerator
|
|
||||||
* str.lines(limit) => anEnumerator
|
|
||||||
* str.lines(sep, limit) => anEnumerator
|
|
||||||
*
|
|
||||||
* Returns an enumerator that gives each line in the string.
|
|
||||||
*
|
|
||||||
* "foo\nbar\n".lines.to_a #=> ["foo\n", "bar\n"]
|
|
||||||
* "foo\nb ar".lines.sort #=> ["b ar", "foo\n"]
|
|
||||||
*/
|
|
||||||
|
|
||||||
static VALUE
|
|
||||||
rb_io_lines(int argc, VALUE *argv, VALUE io)
|
|
||||||
{
|
|
||||||
return rb_enumeratorize(io, ID2SYM(rb_intern("each_line")), argc, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* call-seq:
|
|
||||||
* str.bytes => anEnumerator
|
|
||||||
*
|
|
||||||
* Returns an enumerator that gives each byte in the string.
|
|
||||||
*
|
|
||||||
* "hello".bytes.to_a #=> [104, 101, 108, 108, 111]
|
|
||||||
*/
|
|
||||||
|
|
||||||
static VALUE
|
|
||||||
rb_io_bytes(VALUE io)
|
|
||||||
{
|
|
||||||
return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* call-seq:
|
|
||||||
* ios.chars => anEnumerator
|
|
||||||
*
|
|
||||||
* Returns an enumerator that gives each character in <em>ios</em>.
|
|
||||||
* The stream must be opened for reading or an <code>IOError</code>
|
|
||||||
* will be raised.
|
|
||||||
*
|
|
||||||
* f = File.new("testfile)
|
|
||||||
* f.chars.each {|c| print c, ' ' }
|
|
||||||
*/
|
|
||||||
|
|
||||||
static VALUE
|
|
||||||
rb_io_chars(VALUE io)
|
|
||||||
{
|
|
||||||
return rb_enumeratorize(io, ID2SYM(rb_intern("each_char")), 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* call-seq:
|
|
||||||
* ios.getc => fixnum or nil
|
|
||||||
*
|
|
||||||
* Reads a one-character string from <em>ios</em>. Returns
|
|
||||||
* <code>nil</code> if called at end of file.
|
|
||||||
*
|
|
||||||
* f = File.new("testfile")
|
|
||||||
* f.getc #=> "8"
|
|
||||||
* f.getc #=> "1"
|
|
||||||
*/
|
|
||||||
|
|
||||||
static VALUE
|
|
||||||
rb_io_getc(VALUE io)
|
|
||||||
{
|
|
||||||
rb_io_t *fptr;
|
|
||||||
int r, n;
|
|
||||||
VALUE str;
|
|
||||||
rb_encoding *enc;
|
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
|
||||||
rb_io_check_readable(fptr);
|
|
||||||
|
|
||||||
enc = io_input_encoding(fptr);
|
|
||||||
READ_CHECK(fptr);
|
|
||||||
return io_getc(fptr, enc);
|
|
||||||
}
|
|
||||||
int
|
int
|
||||||
rb_getc(FILE *f)
|
rb_getc(FILE *f)
|
||||||
{
|
{
|
||||||
@ -7064,17 +7005,6 @@ argf_each_byte(VALUE argf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
|
||||||
argf_each_char(VALUE argf)
|
|
||||||
{
|
|
||||||
RETURN_ENUMERATOR(argf, 0, 0);
|
|
||||||
for (;;) {
|
|
||||||
if (!next_argv()) return Qnil;
|
|
||||||
rb_block_call(current_file, rb_intern("each_char"), 0, 0, rb_yield, 0);
|
|
||||||
next_p = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
argf_filename(VALUE argf)
|
argf_filename(VALUE argf)
|
||||||
{
|
{
|
||||||
@ -7373,10 +7303,8 @@ Init_IO(void)
|
|||||||
rb_define_method(rb_cIO, "each", rb_io_each_line, -1);
|
rb_define_method(rb_cIO, "each", rb_io_each_line, -1);
|
||||||
rb_define_method(rb_cIO, "each_line", rb_io_each_line, -1);
|
rb_define_method(rb_cIO, "each_line", rb_io_each_line, -1);
|
||||||
rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0);
|
rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0);
|
||||||
rb_define_method(rb_cIO, "each_char", rb_io_each_char, 0);
|
|
||||||
rb_define_method(rb_cIO, "lines", rb_io_lines, -1);
|
rb_define_method(rb_cIO, "lines", rb_io_lines, -1);
|
||||||
rb_define_method(rb_cIO, "bytes", rb_io_bytes, 0);
|
rb_define_method(rb_cIO, "bytes", rb_io_bytes, 0);
|
||||||
rb_define_method(rb_cIO, "chars", rb_io_chars, 0);
|
|
||||||
|
|
||||||
rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
|
rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
|
||||||
rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1);
|
rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1);
|
||||||
@ -7473,7 +7401,6 @@ Init_IO(void)
|
|||||||
rb_define_method(rb_cARGF, "each", argf_each_line, -1);
|
rb_define_method(rb_cARGF, "each", argf_each_line, -1);
|
||||||
rb_define_method(rb_cARGF, "each_line", argf_each_line, -1);
|
rb_define_method(rb_cARGF, "each_line", argf_each_line, -1);
|
||||||
rb_define_method(rb_cARGF, "each_byte", argf_each_byte, 0);
|
rb_define_method(rb_cARGF, "each_byte", argf_each_byte, 0);
|
||||||
rb_define_method(rb_cARGF, "each_char", argf_each_char, 0);
|
|
||||||
|
|
||||||
rb_define_method(rb_cARGF, "read", argf_read, -1);
|
rb_define_method(rb_cARGF, "read", argf_read, -1);
|
||||||
rb_define_method(rb_cARGF, "readpartial", argf_readpartial, -1);
|
rb_define_method(rb_cARGF, "readpartial", argf_readpartial, -1);
|
||||||
|
@ -1,3 +1,35 @@
|
|||||||
|
class Integer
|
||||||
|
|
||||||
|
def gcd(other)
|
||||||
|
min = self.abs
|
||||||
|
max = other.abs
|
||||||
|
while min > 0
|
||||||
|
tmp = min
|
||||||
|
min = max % min
|
||||||
|
max = tmp
|
||||||
|
end
|
||||||
|
max
|
||||||
|
end
|
||||||
|
|
||||||
|
def lcm(other)
|
||||||
|
if self.zero? or other.zero?
|
||||||
|
0
|
||||||
|
else
|
||||||
|
(self.div(self.gcd(other)) * other).abs
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def gcdlcm(other)
|
||||||
|
gcd = self.gcd(other)
|
||||||
|
if self.zero? or other.zero?
|
||||||
|
[gcd, 0]
|
||||||
|
else
|
||||||
|
[gcd, (self.div(gcd) * other).abs]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
module Math
|
module Math
|
||||||
|
|
||||||
alias exp! exp
|
alias exp! exp
|
||||||
|
@ -15,3 +15,35 @@ class Bignum
|
|||||||
alias rpower **
|
alias rpower **
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Integer
|
||||||
|
|
||||||
|
def gcd(other)
|
||||||
|
min = self.abs
|
||||||
|
max = other.abs
|
||||||
|
while min > 0
|
||||||
|
tmp = min
|
||||||
|
min = max % min
|
||||||
|
max = tmp
|
||||||
|
end
|
||||||
|
max
|
||||||
|
end
|
||||||
|
|
||||||
|
def lcm(other)
|
||||||
|
if self.zero? or other.zero?
|
||||||
|
0
|
||||||
|
else
|
||||||
|
(self.div(self.gcd(other)) * other).abs
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def gcdlcm(other)
|
||||||
|
gcd = self.gcd(other)
|
||||||
|
if self.zero? or other.zero?
|
||||||
|
[gcd, 0]
|
||||||
|
else
|
||||||
|
[gcd, (self.div(gcd) * other).abs]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
1
proc.c
1
proc.c
@ -95,6 +95,7 @@ proc_dup(VALUE self)
|
|||||||
dst->envval = src->envval;
|
dst->envval = src->envval;
|
||||||
dst->safe_level = dst->safe_level;
|
dst->safe_level = dst->safe_level;
|
||||||
dst->special_cref_stack = src->special_cref_stack;
|
dst->special_cref_stack = src->special_cref_stack;
|
||||||
|
dst->is_lambda = src->is_lambda;
|
||||||
|
|
||||||
return procval;
|
return procval;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#define RUBY_VERSION "1.9.0"
|
#define RUBY_VERSION "1.9.0"
|
||||||
#define RUBY_RELEASE_DATE "2008-03-29"
|
#define RUBY_RELEASE_DATE "2008-03-30"
|
||||||
#define RUBY_VERSION_CODE 190
|
#define RUBY_VERSION_CODE 190
|
||||||
#define RUBY_RELEASE_CODE 20080329
|
#define RUBY_RELEASE_CODE 20080330
|
||||||
#define RUBY_PATCHLEVEL 0
|
#define RUBY_PATCHLEVEL 0
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
@ -9,7 +9,7 @@
|
|||||||
#define RUBY_VERSION_TEENY 0
|
#define RUBY_VERSION_TEENY 0
|
||||||
#define RUBY_RELEASE_YEAR 2008
|
#define RUBY_RELEASE_YEAR 2008
|
||||||
#define RUBY_RELEASE_MONTH 3
|
#define RUBY_RELEASE_MONTH 3
|
||||||
#define RUBY_RELEASE_DAY 29
|
#define RUBY_RELEASE_DAY 30
|
||||||
|
|
||||||
#ifdef RUBY_EXTERN
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user