作者歸檔:船長

learning ruby 7, Expressions

[ 3, 1, 7, 0 ].sort.reverse   [7, 3, 1, 0]

Operator Expressions
a*b + c
(a.*(b)).+(c)

Miscellaneous Expressions
Command Expansion
`date`                   "Thu Aug 26 22:36:31 CDT 2004
"
`ls`.split[34]           "book.out"
%x{echo "Hello there"}   "Hello there
"
for i in 0..3
  status = `dbmanager status id=#{i}`
  # …
end

Assignment
a=b=1+2+3
a   →6
b   →6
a = (b = 1 + 2) + 3
a   →6
b   →3

attribute
de?ne a writable object attribute
class Song
  def duration=(new_duration)
    @duration = new_duration
  end
end
attribute assignment
song.duration = 234

Parallel Assignment
swap the values in two variables
a, b = b, a

x=0                               0
a, b, c = x, (x += 1), (x += 1)   [0, 1, 2]

a = [1, 2, 3, 4]
b, c =  a          b == 1,  c == 2
b, *c = a          b == 1,  c == [2, 3, 4]
b, c =  99, a      b == 99, c == [1, 2, 3, 4]
b, *c = 99, a      b == 99, c == [[1, 2, 3, 4]]
b, c =  99, *a     b == 99, c == 1
b, *c = 99, *a     b == 99, c == [1, 2, 3, 4]

Nested Assignments
b, (c, d), e = 1,2,3,4       b == 1, c == 2, d == nil,    e == 3
b, (c, d), e = [1,2,3,4]     b == 1, c == 2, d == nil,    e == 3
b, (c, d), e = 1,[2,3],4     b == 1, c == 2, d == 3,      e == 4
b, (c, d), e = 1,[2,3,4],5   b == 1, c == 2, d == 3,      e == 5
b, (c,*d), e = 1,[2,3,4],5   b == 1, c == 2, d == [3, 4], e == 5

Other Forms of Assignment

Conditional Execution
                                                                       The number zero is not interpreted as a false value. Neither is a zero-length string.

De?ned?, And, Or, and Not
and and or have the same precedence,
&& has a higher precedence than ||.

defined? 1          "expression"
defined? dummy      nil
defined? printf     "method"
defined? String     "constant"
defined? $_         "global-variable"
defined? Math::PI   "constant"
defined? a=1        "assignment"
defined? 42.abs     "method"

Operator     Meaning
==     Test for equal value.
===       Used to compare the each of the items with the target in the when clause of a case statement.
<=>   General comparison operator. Returns −1, 0, or +1, depending on   whether its receiver is less than, equal to, or greater than its argument.
<, <=, >=, >    Comparison operators for less than, less than or equal, greater than or  equal, and greater than.
=~       Regular expression pattern match.
eql?     True if the receiver and argument have both the same type and equal values. 1 == 1.0 returns true, but 1.eql?(1.0) is false.
equal?   True if the receiver and argument have the same object ID.
== and =~ have negated forms, != and !~.

The value of Logical Expressions
nil   and true    nil
false and true    false
99    and false   false
99    and nil     nil
99    and "cat"   "cat"

false or nil     nil
nil   or false   false
99    or false   99

words[key] ||= []
words[key] << word
=====>
(words[key] ||= []) << word

If and Unless Expressions
then
if song.artist == "Gillespie" then handle = "Dizzy"
elsif song.artist == "Parker" then handle = "Bird"
else handle = "unknown"
end

:
if song.artist == "Gillespie": handle = "Dizzy"
elsif song.artist == "Parker": handle = "Bird"
else handle = "unknown"
end

if song.artist == "Gillespie"
  handle = "Dizzy"
elsif song.artist == "Parker"
  handle = "Bird"
else
  handle = "unknown"
end

unless song.duration > 180
  cost = 0.25
else
  cost = 0.35
end
==>
cost = song.duration > 180 ? 0.35 : 0.25

If and Unless Modi?ers
mon, day, year = $1, $2, $3 if date =~ /(\d\d)-(\d\d)-(\d\d)/
puts "a = #{a}" if debug
print total unless total.zero?

Case Expressions
leap years must be divisible by 400, or divisible by 4 and not by 100.
     leap = case
            when year % 400 == 0: true
            when year % 100 == 0: false
            else year % 4       == 0
            end

case input_line
when "debug"
  dump_debug_info
  dump_symbols
when /p\s+(\w+)/
  dump_variable($1)
when "quit", "exit"
  exit
else
  print "Illegal command: #{input_line}"
end

case shape
when Square, Rectangle
  # …
when Circle
  # …
when Triangle
  # …
else
  # …
end

Loops
while line = gets
  # …
end

until play_list.duration > 60
  play_list.add(song_list.pop)
end

a=1
a *= 2 while a < 100
a -= 10 until a < 100
a   → 98

    file = File.open("ordinal")
    while line = file.gets
      puts(line) if line =~ /third/ .. line =~ /fifth/
    end
produces:
    third
    fourth
    fifth

Iterators
    3.times do
      print "Ho! "
    end
produces:
    Ho! Ho! Ho!

    0.upto(9) do |x|
      print x, " "
    end
produces:
    0123456789

    0.step(12, 3) {|x| print x, " " }
produces:
    0 3 6 9 12

    [ 1, 1, 2, 3, 5 ].each {|val| print val, " " }
produces:
    11235

For . . . In
for song in songlist
  song.play
end

    for i in ['fee', 'fi', 'fo', 'fum']
      print i, " "
    end
    for i in 1..3
      print i, " "
    end
    for i in File.open("ordinal").find_all {|line| line =~ /d$/}
      print i.chomp, " "
    end
produces:
    fee fi fo fum 1 2 3 second third

Break, Redo, and Next
while line = gets
  next if line =~ /^\s*#/   # skip comments
  break if line =~ /^END/   # stop at end
                    # substitute stuff in backticks and try again
  redo if line.gsub!(/`(.*?)`/) { eval($1) }
  # process line …
end

Retry
    for i in 1..100
      print "Now at #{i}. Restart? "
      retry if gets =~ /^y/i
    end
Running this interactively, you may see
    Now at 1. Restart? n
    Now at 2. Restart? y
    Now at 1. Restart? n
     …

Variable Scope, Loops, and Blocks
x = nil
y = nil
[ 1, 2, 3 ].each do |x|
  y=x+1
end
[ x, y ]   → [3, 4]

if false
  a=1
end
3.times {|i| a = i }
a        2

發表在 Ruby on Rails | 留下評論

任逍遙,2002

任逍遙,2002
http://www.imdb.com/title/tt0318025/

從這部電影背景可以看得出來賈樟柯 並不是我想象中的那樣馴良,他是有企圖心的。
8

任逍遙,2002
八神 庵(七中)

任逍遙,2002
又見美女

任逍遙,2002
喝蒙古王酒,品馬上人生!

任逍遙,2002
美女和她住的小區

任逍遙,2002
東風不止,可惜無語相和

任逍遙,2002
原來要泡趙濤這麼簡單--只要豁出性命就可以了

任逍遙,2002
別,無吻

任逍遙,2002

任逍遙,2002
任~~逍~~遙~~

發表在 電影評論 | 留下評論

美麗新世界,1999

美麗新世界,1999
http://www.imdb.com/title/tt0191002/
我很不解,既然詭異地使用了任賢齊的照片作為封面,為什麼不打上“亂倫到底”這樣的宣傳口號?
這麼賢惠的陶虹竟然選了一個這樣的角色。。。
影片鏡頭有點亂,故事也不很流暢。
5

美麗新世界,1999
陶虹和小侄一起看電視

美麗新世界,1999
美麗是一種武器

美麗新世界,1999
下面侄子在做什麼呢?

發表在 電影評論 | 留下評論

夢遊夏威夷,2005

夢遊夏威夷,2005
http://www.imdb.com/title/tt0788133/

我對你說哦,全世界你對我最好了. 你知道嗎?其他人都很陰險。
--陳欣欣

6

夢遊夏威夷,2005
可愛的檳榔妹

夢遊夏威夷,2005
正在認真備考的陳欣欣

夢遊夏威夷,2005
應該還有魚吧?

發表在 電影評論 | 留下評論

愛情靈藥,2002

愛情靈藥,2002
http://www.imdb.com/title/tt0373718/
好搞笑的三級電影。

7

發表在 電影評論 | 留下評論

learning ruby 6, about methods

De?ning a Method
Method names should begin with a lowercase letter.
Methods that act as queries are often named with a trailing ?,
Methods that are “dangerous,” or modify the receiver, may be named with a trailing !.
methods that can be assigned to end with an equals sign (=).

def cool_dude(arg1="Miles", arg2="Coltrane", arg3="Roach")
  "#{arg1}, #{arg2}, #{arg3}."
end

def my_other_new_method
  # Code for the method would go here
end

Variable-Length Argument Lists(*, asterisk ->Array)
def varargs(arg1, *rest)
  "Got #{arg1} and #{rest.join(', ')}"
end
varargs("one")                      "Got one and "
varargs("one", "two")    "Got one and two"
varargs "one", "two", "three"       "Got one and two, three"

Methods and Blocks
def take_block(p1)
  if block_given?
    yield(p1)
  else
    p1
  end
end
take_block("no block")                           "no block"
take_block("no block") {|s| s.sub(/no /, '') }   "block"

if the last parameter in a method de?nition is pre?xed with an ampersand(&),any associated block is converted to a Proc object, and that object is assigned to the parameter.

class TaxCalculator
  def initialize(name, &block)
    @name, @block = name, block
  end
  def get_tax(amount)
    "#@name on #{amount} = #{ @block.call(amount) }"
  end
end
tc = TaxCalculator.new("Sales tax") {|amt| amt * 0.075 }
tc.get_tax(100)       "Sales tax on 100 = 7.5"
tc.get_tax(250)       "Sales tax on 250 = 18.75"

Calling a Method

Method Return values
def meth_three
 100.times do |num|
   square = num*num
   return num, square if square > 1000
 end
end
meth_three → [32, 1024]
num, square = meth_three
num      → 32
square   → 1024

Expanding Arrays in Method Calls
def five(a, b, c, d, e)
  "I was passed #{a} #{b} #{c} #{d} #{e}"
end
five(1, 2, 3, 4, 5 )            "I was passed 1 2 3 4 5"
five(1, 2, 3, *['a', 'b'])       "I was passed 1 2 3 a b"
five(*(10..14).to_a)             "I was passed 10 11 12 13 14"

Making Blocks More Dynamic
    print "(t)imes or (p)lus: "
    times = gets
    print "number: "
    number = Integer(gets)
    if times =~ /^t/
      calc = lambda {|n| n*number }
    else
      calc = lambda {|n| n+number }
    end
    puts((1..10).collect(&calc).join(", "))
produces:
    (t)imes or (p)lus: t
    number: 2
    2, 4, 6, 8, 10, 12, 14, 16, 18, 20

Collecting Hash Arguments
class SongList
  def create_search(name, params)
    # …
  end
end

list.create_search('short jazz songs',
                   :genre              => :jazz,
                   :duration_less_than => 270)

發表在 Ruby on Rails | 留下評論

門徒,2007

門徒,2007

http://www.imdb.com/title/tt0841150/

毒庄,毒販,吸毒者,緝毒警摻雜到一起時發生的故事。

7

門徒,2007
6年前劉德華用同樣的眼神宣傳香港新警匪片時代開始

門徒,2007
美麗的罌粟花

發表在 電影評論 | 2 條評論

南國再見,南國,1996

南國再見,南國,1996
http://www.imdb.com/title/tt0117151/
小高、扁頭、小麻花、還有來去不定的瑛姐在南台灣的故事。
原來台灣也有不錯的電影,台灣電影人中原來有一個叫
侯孝賢。

8

南國再見,南國,1996
好大的日曆

南國再見,南國,1996
扁頭 ,伊能靜, 大哥,還有南台灣

發表在 電影評論 | 留下評論

賈樟柯--追求並堅持自己夢想的人

記賈樟柯講座錄音

賈樟柯--追求並堅持自己夢想的人

追尋夢想
賈樟柯1970年出生在山西省汾陽一個小縣城裡。
賈樟柯--追求並堅持自己夢想的人

賈樟柯高中時是學畫畫,但相比他也許更喜歡寫小說。因為在他感覺畫畫能表達的只是瞬間,而他卻有很強的時間觀,他想要表述流動的生活。畫面上瞬間的定格之所以能讓某人感觸,除了那畫面,而且還因為那個有過去,有將來的看畫的人。

賈樟柯說一天他走在熟悉的小城的路上,向家裡送煤的路上,突然聽到巨大的聲響,抬頭一看是一直升飛機從頭上飛過,看着這飛機他愣住了,因為這是小城到目前為止發生的最意外的事。 這個畫面給他的印象很深。之所以會給他留下這麼深的印象,不是因為那畫面怎樣壯觀,而是因為這個小城和在這裡生活了這麼多年的賈樟柯。
賈樟柯--追求並堅持自己夢想的人
偶然的機會賈樟柯看到了張藝謀的<黃土地>,這讓他發現了新大陸,讓他明白這就是我想要的!電影!他要考電影學院。

靠近夢想
賈樟柯想報攝影,因為這個要考畫畫,而畫畫是他的本行,我想或也因為“攝影“從名詞上說是和流動的時間+畫畫最接近的職業,而且他又想到張藝謀也是攝影出身,但因為身高限制不能報考,之後想報導演,但同學說這個競爭太大,所以他報了文學系,他的想法很單純,如果不能得到,就算退而求而次,他要接近電影!
賈樟柯--追求並堅持自己夢想的人
找遍小城,賈樟柯只找到兩本和電影勉強相關的輔導書,開始學習,這時他20歲,在這個小城裡這是個可以有孩子的年紀了, 但賈樟柯一心想要上電影學院。考了三年,1993年23歲的他終於考上了北京電影學院文學系。

窺探世間的人
一張照片,他可以想出一個世界。

堅持夢想
電影學院有圖書館,這裡的書小城是看不到的, 而且可以經常看電影,也有同學可以討論,這是賈樟柯對大學裡老師之外的資源的樂觀看法。看來他沒有浪費他的大學時光。
在看了很多電影之後,賈樟柯失望了,他沒能在銀幕上找到“黃土地”,沒能看了那片他曾經在那割麥過的田野,電影上更多的鏡頭是兩個時髦女郎在談論上星期的巴黎之行。。。
同樣在銀幕下也有讓賈樟柯意外的事。他發現一些和他同鄉的朋友在北京不但不談論自己的小城,而且還避開那個地方。。。
賈樟柯卻對那個小城和小城上的人,小城上的事情有獨鍾。他認為那是真正的生活,平凡,平淡,卻真實。 他認為中國還是個農業社會,更多的人還是農民,城市中的人很多也是從農村中來的。 而農村,這個主要的中國生活在電影上卻很少見。

賈樟柯在大學期間(1995年)受<獨立電影製作>啟發,和同學組成了 北京電影學院青年實驗電影小組, 並找錢(應該不超過5萬)拍了一部電影<小山回家>,講述一個農民工回家前找結伴同鄉的過程。器材大多是借的,職員大多是同學。
賈樟柯--追求並堅持自己夢想的人
在宿舍的“首映“遭遇冷場,賈樟柯曾經心灰意冷,但後來到北大放映後,賈樟柯看着北大同學對自己影片熱烈評論,又感覺自己做對了一件事。後來賈樟柯也說這部不成熟的電影讓他熟悉了電影製作。

賈樟柯--追求並堅持自己夢想的人
其實<小山回家>帶給賈樟柯的遠不止這些--後來一個在報社工作的學姐把<小山回家>登到了一份報紙上,而這報紙引來了一香港電視台的採訪,而這次採訪的主持人一句話讓賈樟柯知道了香港的一個短片展,之後才有了<小山回家>的參展香港,這才使賈樟柯結實了香港一位製片人,於是就有了1997年的<小武>--這是賈樟柯的第一部意義上的電影,作為<故鄉三部曲>之一,這部作為描寫山西汾陽小城的電影正是賈樟柯夢想的起飛點。。。

發表在 成敗幾何, 電影評論 | 留下評論

XHTML Quick Reference

Basic XHTML Rules

    * 使用小寫標籤:
      <p class="introduction">Paragraph text</p>
    *使用雙引號:
      <a href="calendar.php">
    *外部鏈接使用http://開頭:
      <a href="http://www.cnn.com/";>Latest news.</a>
    * <br />,<img />等標籤關閉前加一空格。:

      <img src="funnyface.jpg" alt="Me making a funny face." />
    * 標籤要關閉:
      <h1>Welcome to English 106</h1>
    * 標籤嵌套要順序進行:

發表在 站長文檔 | 留下評論