Re: [問題] 如何新增變數?
新增變數? @_@b
※ 引述《forkome (丁丁是個人材)》之銘言:
: 問題一
: v = 1
: k = v
: 目前k對印的記憶體位置跟v一樣
^^^^ 對(應|映) ?
: 我想讓k有自己的記憶體位置
: java的話是 String k = new String
java 不能省略 new String() 中的括號 XD
: 若ruby的話要怎麼做呢?
Fixnum 是 constant, 永遠不能產生一個相同的 Fixnum
irb(main):001:0> 1.dup
TypeError: can't dup Fixnum
你想要的話可以自己做 wrapper
class MyInteger
attr_accessor :data
end
: 問題二、Do while問題
: 書上有教使用
: while 條件
: .
: .
: end
: 是否有
: do
: .
: .
: while 條件
: 的用法呢?
就我所知沒有...
不過有其他的變形:
until condition
end
expression while condition
expression until condition
--
#!/usr/bin/ruby [露比] /Programming (Kn|N)ight/ 看板《Ruby》
# if a dog nailed extra legs that http://www.ptt.cc/bbs/Ruby/index.html
# walks like an octopus, and Welcome ~Ruby@ptt~
# talks like an octopus, then ◢█◣ http://www.ruby-lang.org/
# we are happy to treat it as █ http://www.ruby-doc.org/
# if it were an octopus. ◥ ◤ http://www.rubyforge.org/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.28.18
推
11/20 19:22, , 1F
11/20 19:22, 1F
→
11/20 19:51, , 2F
11/20 19:51, 2F
→
11/21 21:26, , 3F
11/21 21:26, 3F
討論串 (同標題文章)