Ruby memo

catchthrow 


Kernelcatchthrow便

catchthrow使
 
#!/usr/local/bin/ruby22

p "1"
catch(:tag){
  p "2"
  throw(:tag)
  p "3"
}
p "4"

使catchthrowtag
 
#!/usr/local/bin/ruby22

def foo()
  p "foo-1"
  catch(:mytag){
    p "foo-2"
    yield()
    p "foo-3"
    throw(:mytag)
    p "foo-4"
  }
  p "foo-5"
end

def bar()
  p "bar-1"
  catch(:mytag){
    p "bar-2"
    foo(){
      p "bar-3"
      throw(:mytag)
      p "bar-4"
    }
    p "bar-5"
  }
  p "bar-6"
end

bar()


 
"bar-1"
"bar-2"
"foo-1"
"foo-2"
"bar-3"  # ここに
"foo-5"  # 注意
"bar-5"
"bar-6"

barthrowfoocatchcatch/throw調使

rubycatchthrowthrow
 
#!/usr/local/bin/ruby22

p "1"
catch {|tag_obj|
  p tag_obj
  throw(tag_obj)
  p "3"
}
p "4"

tag_objrubyopaque使catch使


 gem ruby 

cruby (MRI) 

rubygem 

=~ 


Perl  Awk  ~ Ruby Perl 

NArray 使


ruby 

NArray 使 NArray 

NArray 


NArray  http://narray.rubyforge.org/index.html.ja 使 rubygem ruby 

Cruby  foo[i][j]  Basic  Fortran  foo[j, i] ruby  Array 使使

 http://www.slideshare.net/masa16tanaka/narray-pwrake 

使

Java 3D 使Python  NumPy Python  foo += bar  foo = foo + bar 

1 


PC100 Array#sort! 

 NArray 使


array_sort.rb

narray_sort.rb
 

 500 
 
$ ruby19 -v array_sort.rb 5000000
ruby 1.9.3p125 (2012-02-16 revision 34643) [amd64-freebsd8]
13.510852
13.427535
13.424106
13.445138
13.704523
13.864022
13.632735
13.586616
13.757978
13.65584
13.562891
13.637271
13.846052
13.541271
13.626213
13.648054
13.401002
13.550984
13.689528
13.425835
$ ruby19 -v narray_sort.rb 5000000
ruby 1.9.3p125 (2012-02-16 revision 34643) [amd64-freebsd8]
lib/complex.rb is deprecated
1.269857
1.261399
1.2575
1.268182
1.267217
1.261881
1.263131
1.263579
1.282607
1.263385
1.261822
1.264086
1.267125
1.264541
1.263302
1.260111
1.260393
1.265207
1.271147
1.26037

2 


3 NArray  NMatrix  NVector 使

 Wikipedia  system of linear equations   2012 4
  3 x +  2 y -  z =  1 2 x -  2 y +  4 z =  -  2 -  x +   1 2 y -  z =  0  
3

11CADp. 22 

NArray  NMatrix  NVector  *  NVector 


  3 2 -  1 2 -  2 4 -  1 1 2 -  1 x y z =   1 -  2 0  
NArray 
 
require "narray"

a = NMatrix[
  [ 3.0,  2.0, -1.0],
  [ 2.0, -2.0,  4.0],
  [-1.0,  0.5, -1.0]]

b = NVector[
   1.0,
  -2.0,
   0.0]

baNArray  b/a ba (x y z)T  b/a ab使 [ruby-list:48724]  NArray LU a.lu.solve(b) b/a  solve 

 NMatrix#transpose 
 
p b/a


 
$ ruby19 linear_equations.rb
NVector.float(3):
[ 1.0, -2.0, -2.0 ]

kind_of?  is_a?


 kind_of?  http://jp.rubyist.net/magazine/?0011-CodeReview#l13 

 Module#=== case obj when Klass 使case when  === 

instance_of?


Java  instanceof  (Java) Class#isInstance  Ruby  Object#instance_of? 使Ruby  Object#instance_of? obj.instance_of? klass obj  klass  true 使

String 


 String#size UTF-8  String#length  String#bytesize 使Ruby 1.9

 do end  {}


Ruby 1 do/end 使 Ruby 2§2.6

do ... end使  Ruby

稿Ruby  - 6.1 OKI 


 
irb> File.open 'input.txt'{|file|p file.readlines}
SyntaxError: (irb):**: syntax error, unexpected '{', expecting $end
File.open 'input.txt'{|file|p file.readlines}
                       ^
        from /usr/local/bin/irb19:12:in `
'


 
irb> name = 'input.txt' ; File.open name{|file|p file.readlines}
NoMethodError: undefined method `name' for main:Object
        from (irb):**
        from /usr/local/bin/irb19:12:in `
'

doend 
 
irb> File.open 'input.txt' do|file|p file.readlines end
irb> name = 'input.txt' ; File.open name do|file|p file.readlines end


 
irb> File.open('input.txt'){|file|p file.readlines}
irb> name = 'input.txt' ; File.open(name){|file|p file.readlines}


parenthesize argument(s) for future version

RubyConf使1使 http://route477.net/d/?date=20081019 
 
$ svn diff -r 13820:13821
Index: ChangeLog
===================================================================
--- ChangeLog (revision 13820)
+++ ChangeLog (revision 13821)
@@ -1,3 +1,10 @@
+Mon Nov  5 01:20:33 2007  Yukihiro Matsumoto  <matz@ruby-lang.org>
+
+ * parse.y (call_args): remove "parenthesize argument(s) for future
+   version" warning.  when I added this warning, I had a plan to
+   reimplement the parser that is simpler than the current one.
+   since we abandoned the plan, warning no longer required.
+
 Mon Nov  5 01:02:56 2007  Minero Aoki  <aamine@loveruby.net>
 
  * lib/net/http.rb (HTTPHeader#initialize): provide default
Index: lib/rss/atom.rb
(略)
Index: parse.y
===================================================================
--- parse.y (revision 13820)
+++ parse.y (revision 13821)
@@ -2287,7 +2287,6 @@
 
 call_args : command
       {
-   rb_warn0("parenthesize argument(s) for future version");
       /*%%%*/
    $$ = NEW_LIST($1);
       /*%

\A  \G 


Ruby  \A ruby 1.9  match 2 nth > 0 
 
irb(main):001:0> /\A/.match "foo", 1
=> nil

 \G 使

StringScan  str[nth, -1]  \A 
 
irb(main):001:0> ss = StringScanner.new "foo"
=> #<StringScanner 0/3 @ "foo">
irb(main):002:0> ss.scan /\A./
=> "f"
irb(main):003:0> ss.scan /\A./
=> "o"
irb(main):004:0> ss.scan /\A./
=> "o"
irb(main):005:0> ss.scan /\A./
=> nil

 StringScan  \A 

[ruby-list:47065] 

proc  lambda  Proc.new


proc  obsolete  http://jp.rubyist.net/magazine/?0001-Hotlinks : 

Kernel#lambda 使 Ruby 2Kernel#proc  proc  lambda  Ruby 2Kernel#lambda 
 
procやlambdaをブロックなしで呼び出し、現在のメソッドに与えら
れているブロックをオブジェクト化する機能は、ブロック引数
(&block)またはProc.newに任されました。将来はprocやlambdaには
この機能がなくなります。

 [ruby-list:38044] lambda 


Depq


http://redmine.ruby-lang.org/wiki/ruby/DeveloperHowtoJa



make btest-ruby OPTS="--sets=hoge"
 

ELIS 



Ruby  Lisp-2

S Lisp Matz Lisp  Ruby  Lisp 
 

!


! nil  [ruby-list:47807] !

/usr/local ...


/usr/local configure  --prefix --with-opt-dir=/usr/local configure  configure: WARNING: unrecognized options: --with-opt-dir 

make main


 make main  trunk  1.8  r22592  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=22592 git svn 使
 
REVISION=`git svn info | grep '^Revision: ' | awk '{print $2}'`
make `test $REVISION -ge 22592 && echo main`

Obsolete


http://www.ruby-lang.org/ja/old-man/html/obsolete.html


Ruby  MRI boron  www.ruby-lang.org hydrogen  helium 使