Hatena::Grouprubyist

うんたらかんたらRuby RSSフィード

2010-03-08script/console

script/console

| script/console - うんたらかんたらRuby を含むブックマーク はてなブックマーク - script/console - うんたらかんたらRuby

Railscasts - Console Tricks

より


期待せずに見たが、知らんことだらけだった。


--sandbox

rollbackしてくれると。

$ ruby script/console --help
Usage: console [environment] [options]
    -s, --sandbox                    Rollback database modifications on exit.
        --irb=[irb]                  Invoke a different irb.
        --debugger                   Enable ruby-debugging for the console.


y

なんぞ。yamlに変換してくれるんか。

>> m = Memo.all
=> [#<Memo id: 1, title: "a", body: "", created_at: "2010-02-28 06:56:26", updated_at: "2010-02-28 06:56:26">, #<Memo id: 2, title: "aaa", body: "bbb", created_at: "2010-02-28 06:56:39", updated_at: "2010-02-28 06:56:39">]
?> y m
--- 
- !ruby/object:Memo 
  attributes: 
    created_at: 2010-02-28 06:56:26
    title: a
    body: ""
    updated_at: 2010-02-28 06:56:26
    id: "1"
  attributes_cache: {}

- !ruby/object:Memo 
  attributes: 
    created_at: 2010-02-28 06:56:39
    title: aaa
    body: bbb
    updated_at: 2010-02-28 06:56:39
    id: "2"
  attributes_cache: {}

=> nil

ri y

--------------------------------------------------------------- Kernel#y
     y( object, *objects )
------------------------------------------------------------------------
     Prints any supplied _objects_ out in YAML. Intended as a variation
     on +Kernel::p+.

       S = Struct.new(:name, :state)
       s = S['dave', 'TX']
       y s

     _produces:_

       --- !ruby/struct:S
       name: dave
       state: TX

methods検索

controllerの〜pathってなんだっけって時はgrepも使える。

?> app.class
=> ActionController::Integration::Session

?>app.methods.grep(/_path$/).sort
=> ["edit_memo_path", "edit_polymorphic_path", "formatted_edit_memo_path", "formatted_memo_path", "formatted_memos_path", "formatted_new_memo_path", "formatted_polymorphic_path", "hash_for_edit_memo_path", "hash_for_memo_path", "hash_for_memos_path", "hash_for_new_memo_path", "memo_path", "memos_path", "new_memo_path", "new_polymorphic_path", "polymorphic_path"]

_

前回の実行結果が出力可能

>> y _
--- 
- edit_memo_path
- edit_polymorphic_path
- formatted_edit_memo_path
- formatted_memo_path
- formatted_memos_path
- formatted_new_memo_path
- formatted_polymorphic_path
- hash_for_edit_memo_path
- hash_for_memo_path
- hash_for_memos_path
- hash_for_new_memo_path
- memo_path
- memos_path
- new_memo_path
- new_polymorphic_path
- polymorphic_path
=> nil
トラックバック - http://rubyist.g.hatena.ne.jp/rochefort/20100308