作者归档:船长

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>
    * 标签嵌套要顺序进行:

发表在 站长文档 | 留下评论