so that 構文の4種類の用法
当時、筆者が中学で習った so that 構文は「とても~なので…です」 と1種類だけなので容易に覚えることができました。 しかしながら、仕事で英語に触れる機会が増えてくると、上と似たような so that が出てくる文章ではあるけれども、上の意味で訳すとどうも意味が通らないケースが多いのです。 そこでよくよく調べてみますと、 so that 構文には4種類の用法がありました。
1. 程度・結果(~するほど...だ、とても...なので~だ)
so の後に 形容詞か副詞
がきます。
まずは中学英語で習った so that 構文ですね。
He is so hungry, that he can eat anything. (彼はなんでも食べられる程空腹だ。)
too~ to... (あまりに~すぎて、... できない) と書き換えさせる問題がよく出題されました。
2. 様態(~するように...)
so の後に 過去分詞
がきます。
This bicycle is so made that it drives speedy. (この自転車は早く走れるように作られている。)
様態とは聞き慣れない言葉ですが、「物事のありかた。様相」という意味です。
3. 目的(~するために...)
so と that がくっついています。
後節が目的を示す節となっています。
I work so that I earn money for tuition of university. (私は大学の学費を稼ぐために働いている。)
The Architecture of Open Source Applications (Volume 2): nginx の 14.4. nginx Internals を読んでいて見つけたので訳してみます。
For a directory it would automatically rewrite the URI so that the trailing slash is always there (and then issue an HTTP redirect). (ディレクトリの場合は、trailing slash を付加するために自動的でURIに変換されます。その後、HTTP リダイレクトが行われます。)
4. 結果(~その結果...)
- のパターンに加えてカンマが先頭につきます。
I study hardly, so that I passed the difficult examination. (ハードに勉強した。その結果、難しい試験をパスした。)
省略について
so that 構文では、口語では that が, 文語では so が省略されることがよくあるようです。
- 口語
I study hardly, so I passed the difficult examination.
- 文語
I study hardly, that I passed the difficult examination.
うーん。口語の方はわかるんですが、文語の方はこの事をわかってないと、なかなか意味を取るのは難しそうですね。 初期に習う単語ほど、色々な語法が多くて混乱の要因になることが多い気がします。
参考にした記事
こちらの記事を参考にさせていただきました。ありがとうございます!
Rubyでグラフを表現してみる
class Vertex attr_accessor :id, :edges def initialize(id, edges=[]) @id = id @edges = edges end def print puts "#{ @id }" @edges.each do |edge| puts edge end end end class Edge attr_accessor :id, :from, :to, :length def initialize(id, from, to, length) @id = id @from = from @to = to @length = length end def to_s "#{ from } => #{ to } #{ length }" end end class Graph attr_accessor :vertexes, :edges def initialize(data) @vertexes = [] data.each do |k, v| edges = [] v.each do |k2, v2| edges << Edge.new( 0, k ,k2, v2 ) end @vertexes << Vertex.new( k, edges ) end end def print_graph @vertexes.each do |v| v.print end end end data = { a: {b: 1, c: 3, d: 4}, b: {b: 3, d: 11}, c: {a: 1}, d: {e: 11}, e: {a: 1}, } g = Graph.new( data ) g.print_graph
実行結果
a a => b 1 a => c 3 a => d 4 b b => b 3 b => d 11 c c => a 1 d d => e 11 e e => a 1
Kernel#systemと`` の挙動の違い
戻り値
p system "ls" # => true p `ls` # => "Capfile\nGemfile\nGemfile.lock\n...."
エラー時の挙動
p system "ls2" # => nil p `ls2` # => No such file or directory - ls2 (Errno::ENOENT) の例外が発生し、 空文字列がかえる
p ls2
の例については begin, rescue で囲って動作確認した。
RubyMineでファイルのシンタックスハイライトが効かないときの対応方法
bash
のコードは拡張子がなくてRubyMine側がファイルの種類を判断できなかったりするので、自分で指定する必要がある。
Help > Find Action... > Action > Associate with File Type...
で指定できる。
Find Action
は shift 2回でも起動できる。
ローカルにある不要になった remote-tracking branch を削除する
remote-tracking branch を削除する方法
remote-tracking branch とはローカルにあるリモートレポジトリの追跡ブランチのことです。
私たちが手元で使うローカルブランチは、 git fetch して、このremote-tracking branch をローカルに作成した後に、
ここからさらに git checkout -b して生成されます。
開発が終わり、無事マージした後にこの remote-tracking branch は不要になります。
remote (ex. GitHub上) で削除済みのブランチであれば git remote prune origin
で消せるのですが、
そうでないブランチは消せません。しかし、以下の方法で消すことができます。
%w( origin/test origin/fix origin/fix_typo ).each do |bra| system("git branch -d -r #{ bra }") end
削除前は、 git status, git diff などのコマンドが重かったのですが、実行後は幾分か軽くなりました。
参考にさせていただきました
追記
`git branch --all`.split("\n").map(&:strip).select{|s| s.match(/^remotes\//)}.each do |bra| system("git branch -d -r #{ bra.gsub(/^remotes\//, "") }") end
Rubyの細かい記法のメモ
begin, end で複数行をインスタンス変数にキャッシュできる
def calc_camage(base) # 最終値={基本値×(1-1/8)×武器補正×攻撃回数} base * (1-1/8) * 8 * 1 end def damage @damage ||= begin atk = 12 dfn = 9 base = atk/2 - dfn/4 calc_camage(base) end end p damage # => 32
文字列の展開をまとめて行う
ar = (1..10).to_a puts ("%03d " * 10) % ar # => 001 002 003 004 005 006 007 008 009 010
Array#assoc, rassoc
2次元配列をHashっぽく操作できる。多分名前の由来は英語の association 。
a2 = [ [:a, 1], [:b, 2], [:c, 3], ] p a2.assoc(:a) # => 1 p a2.rassoc(3) # => :c
Hashにもある。
h = {a: 1, b: 2, c: 3} p h.assoc(:a) # => [:a, 1] p h.select{|k,v| k==:a} # => {:a=>1}
ヒアドキュメント
インデントを気にしなくて良い<<~
は2.3 から入った。
なので、それ以前のバージョンでは <<-
を使う必要がある。
#{}
による変数展開も使える。
age = 33 sql = <<~SQL select * from users where age == #{ age } ; SQL puts sql
引数部分にヒアドキュメントを直接指定もできる。
def foo(arg) puts arg end foo(<<-SQL select * from users where id = 1 ; SQL ) # => select * from users # where id = 1 # ;
at_exit でプログラムの最後に実行できる処理を指定できる
END でも可。後から順に実行される。
at_exit { p 1 } at_exit { p 2 } at_exit { p 3 } END { p 4 } END { p 5 } END { p 6 } # => # 6 # 5 # 4 # 3 # 2 # 1
変数名などにUTF8の文字を使える
ただ、クラス名は頭文字が大文字の半角英字である必要がある。
日本語のメソッド名が書けたりする。
class Nucoぬこ def self.新規作成 new end def 鳴く( 回数 = 1 ) puts "にゃーん" * 回数 end end Nucoぬこ.新規作成.鳴く( 3 ) # => にゃーんにゃーんにゃーん