marg-do's

関数型生活

2014-02-01から1ヶ月間の記事一覧

Rubyは再帰呼び出しを何回出来るか

def endless(x) endless(x-1) if x != 1 end i=1 while(true) do puts i endless(i) i+=1 end 環境によっても違うのかもしれませんが、8735で止まった。

selfとはインスタンス自身の参照である

class Test def initialize @num = 5 end def cp self end attr_accessor :num end test = Test.new test2 = test.cp test2.num=3 pp test.num #=>3 pp test2.num #=>3 より明らか

配列に定義された定数とは?

プログラミング言語 Ruby(93p)にて、以下の様なコードがあった modules[0]::NAME 配列内に存在する定数を参照しているようだが、一体どのように定義できるのか? class Test NAME = "aaa" end modules = Array.new modules[0] = Test.new puts modules[0]::N…