PageRenderTime 57ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/radrails_ruby.yml

https://github.com/felixgao/chitsheet
YAML | 789 lines | 547 code | 241 blank | 1 comment | 0 complexity | 1b1b0890812b329e9a71a9fc54059716 MD5 | raw file
  1. ---
  2. radrails_ruby: |-
  3. -- RadRails Ruby Cheat Sheet --
  4. all
  5. all? { |${e}| ${cursor} }
  6. am
  7. alias_method :${new_name}, :${old_name}
  8. any
  9. any? { |${e}| ${cursor} }
  10. app
  11. if __FILE__ == $$PROGRAM_NAME
  12. ${cursor}
  13. end
  14. Array
  15. Array.new(${10}) { |${i}|${cursor} }
  16. art
  17. assert_redirected_to :action => "${index}"
  18. as
  19. assert(${test}, "${message}")
  20. asa
  21. assert(${var} = assigns(:${var}), "@${var} should be defined")
  22. ase
  23. assert_equal(${expected}, ${actual})
  24. asid
  25. assert_in_delta(${expected_float}, ${actual_float}, ${20})
  26. asio
  27. assert_instance_of(${ExpectedClass}, ${actual_instance})
  28. asko
  29. assert_kind_of(${ExpectedKind}, ${actual_instance})
  30. asm
  31. assert_match(/${expected_pattern}/, ${actual_string})
  32. asn
  33. assert_nil(${instance})
  34. asne
  35. assert_not_equal(${unexpected}, ${actual})
  36. asnm
  37. assert_no_match(/${unexpected_pattern}/, ${actual_string})
  38. asnn
  39. assert_not_nil(${instance})
  40. asnnv
  41. assert_not_nil(${var} = assigns(:${var}))
  42. asnr
  43. assert_nothing_raised(${Exception}) { ${cursor} }
  44. asns
  45. assert_not_same(${unexpected}, ${actual})
  46. asnt
  47. assert_nothing_thrown { ${cursor} }
  48. aso
  49. assert_operator(${left}, :${operator}, ${right})
  50. asr
  51. assert_raise(${Exception}) { ${cursor} }
  52. asrdt
  53. assert_redirected_to(${path}, '${message}')
  54. asre
  55. assert_response :${success}
  56. asrt
  57. assert_respond_to(${object}, :${method})
  58. ass
  59. assert_same(${expected}, ${actual})
  60. ass
  61. assert_send([${object}, :${message}, ${args}])
  62. ast
  63. assert_throws(:${expected}) { ${cursor} }
  64. b
  65. =begin rdoc
  66. ${cursor}
  67. =end
  68. begin
  69. begin
  70. ${paste}
  71. rescue ${Exception} => ${e}
  72. ${cursor}
  73. end
  74. bm
  75. TESTS = ${10_000}
  76. Benchmark.bmbm(${10}) do |results|
  77. ${cursor}
  78. end
  79. bt
  80. belongs_to :${object}
  81. btf
  82. belongs_to :${object}, :class_name => '${class_name}', :foreign_key => :${foreign_key}
  83. case
  84. case ${object}
  85. when ${condition}
  86. ${cursor}
  87. end
  88. cl
  89. classify { |${e}| ${cursor} }
  90. cla
  91. class ${ClassName} < DelegateClass(${ParentClass})
  92. def initialize${1}
  93. super(${del_obj})
  94. ${cursor}
  95. end
  96. end
  97. cla
  98. class ${ClassName} < ${ParentClass}
  99. def initialize${1}
  100. ${cursor}
  101. end
  102. end
  103. cla
  104. class ${ClassName} < Struct.new(:${attr_names})
  105. def initialize(*args)
  106. super
  107. ${cursor}
  108. end
  109. end
  110. cla
  111. class ${ClassName}
  112. ${cursor}
  113. end
  114. cla
  115. class ${ClassName}
  116. def initialize${1}
  117. ${cursor}
  118. end
  119. end
  120. cla
  121. class << ${self}
  122. ${cursor}
  123. end
  124. cla
  125. class ${BlankSlate}
  126. instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A__/ }
  127. def initialize${var}
  128. @${delegate} = ${delegate_object}
  129. ${cursor}
  130. end
  131. def method_missing(meth, *args, &block)
  132. @${delegate}.send(meth, *args, &block)
  133. end
  134. end
  135. clafn
  136. split("::").inject(Object) { |par, const| par.const_get(const) }
  137. class
  138. class ${ClassName}
  139. ${cursor}
  140. end
  141. col
  142. collect { |${e}| ${cursor} }
  143. collect
  144. collect { |${element}| ${element}.${cursor} }
  145. Comp
  146. include Comparable
  147. def <=>(other)
  148. ${cursor}
  149. end
  150. dee
  151. Marshal.load(Marshal.dump(${obj_to_copy}))
  152. def
  153. def ${method_name}
  154. ${cursor}
  155. end
  156. defd
  157. def_delegator :${del_obj}, :${del_meth}, :${new_name}
  158. defds
  159. def_delegators :${del_obj}, :${del_methods}
  160. deff
  161. def ${method_name}
  162. ${cursor}
  163. end
  164. defs
  165. def self.${class_method_name}
  166. ${cursor}
  167. end
  168. deft
  169. def test_${case_name}
  170. ${cursor}
  171. end
  172. deli
  173. delete_if { |${e}| ${cursor} }
  174. det
  175. detect { |${e}| ${cursor} }
  176. Dir
  177. Dir.glob(${glob}) { |${file}| ${cursor} }
  178. do
  179. do
  180. ${cursor}
  181. end
  182. doo
  183. do |${object}|
  184. ${cursor}
  185. end
  186. dow
  187. downto(${0}) { |${n}|${cursor} }
  188. ea
  189. each { |${e}| ${cursor} }
  190. eab
  191. each_byte { |${byte}| ${cursor} }
  192. eac
  193. each_char { |${chr}| ${cursor} }
  194. eac
  195. each_cons(${2}) { |${group}| ${cursor} }
  196. each
  197. each { |${element}| ${element}.${cursor} }
  198. each_with_index
  199. each_with_index { |${element}, ${idx}| ${element}.${cursor} }
  200. eai
  201. each_index { |${i}| ${cursor} }
  202. eak
  203. each_key { |${key}| ${cursor} }
  204. eal
  205. each_line${1} { |${line}| ${cursor} }
  206. eap
  207. each_pair { |${name}, ${val}| ${cursor} }
  208. eas
  209. each_slice(${2}) { |${group}| ${cursor} }
  210. eav
  211. each_value { |${val}| ${cursor} }
  212. eawi
  213. each_with_index { |${e}, ${i}| ${cursor} }
  214. elsif
  215. elsif ${condition}
  216. ${cursor}
  217. Enum
  218. include Enumerable
  219. def each(&block)
  220. ${cursor}
  221. end
  222. fet
  223. fetch(${name}) { |${key}|${cursor} }
  224. fil
  225. fill(${range}) { |${i}|${cursor} }
  226. File
  227. File.foreach(${file}) { |${line}| ${cursor} }
  228. fin
  229. find { |${e}| ${cursor} }
  230. fina
  231. find_all { |${e}| ${cursor} }
  232. fl
  233. flunk("${message}")
  234. flao
  235. inject(Array.new) { |${arr}, ${a}| ${arr}.push(*${a}) }
  236. flash
  237. flash[:${notice}] = "${Successfully}"${cursor}
  238. forin
  239. for ${element} in ${collection}
  240. ${element}.${cursor}
  241. end
  242. Forw
  243. extend Forwardable
  244. gre
  245. grep(${pattern}) { |${match}| ${cursor} }
  246. gsu
  247. gsub(/${pattern}/) { |${match}|${cursor} }
  248. habtm
  249. has_and_belongs_to_many :${object}
  250. Hash
  251. Hash.new { |${hash}, ${key}| ${hash}[${key}] = ${cursor} }
  252. hm
  253. has_many :${models}
  254. hmf
  255. has_many :${models}, :class_name => '${class_name}', :foreign_key => :${foreign_key}
  256. hmt
  257. has_many :${models}, :through => :${join_models}
  258. ho
  259. has_one :${model}
  260. hof
  261. has_one :${model}, :class_name => '${class_name}', :foreign_key => :${foreign_key}
  262. hp
  263. :${key} => ${value}
  264. if
  265. if ${condition}
  266. ${cursor}
  267. end
  268. ife
  269. if ${condition}
  270. ${2}
  271. else
  272. ${3}
  273. end
  274. inj
  275. inject(${init}) { |${mem}, ${var}| ${cursor} }
  276. inject
  277. inject(${object}) { |${injection}, ${element}| ${4} }${cursor}
  278. lam
  279. lambda { |${args}|${cursor} }
  280. log
  281. logger.debug "${message}"${cursor}
  282. loge
  283. logger.error "${message}"${cursor}
  284. logf
  285. logger.fatal "${message}"${cursor}
  286. logi
  287. logger.info "${message}"${cursor}
  288. logw
  289. logger.warn "${message}"${cursor}
  290. mac
  291. add_column :${table}, :${column}, :${string}
  292. map
  293. map { |${e}| ${cursor} }
  294. mapwi
  295. enum_with_index.map { |${e}, ${i}| ${cursor} }
  296. max
  297. max { |a, b| ${cursor} }
  298. mcc
  299. t.column :${title}, :${string}${cursor}
  300. mccc
  301. t.column :${title}, :${string}
  302. mccc${cursor}
  303. mct
  304. create_table :${table} do |t|
  305. ${cursor}
  306. end
  307. Md
  308. File.open(${dump}, "w") { |${file}| Marshal.dump(${obj}, ${file}) }
  309. mdt
  310. drop_table :${table}
  311. ${cursor}
  312. min
  313. min { |a, b| ${cursor} }
  314. Ml
  315. File.open(${dump}) { |${file}| Marshal.load(${file}) }
  316. mm
  317. def method_missing(meth, *args, &block)
  318. ${cursor}
  319. end
  320. mnc
  321. rename_column :${column}, :${new_column}
  322. mnt
  323. rename_table :${table}, :${new_name}${cursor}
  324. mod
  325. module ${ModuleName}
  326. module ClassMethods
  327. ${cursor}
  328. end
  329. extend ClassMethods
  330. def self.included(receiver)
  331. receiver.extend(ClassMethods)
  332. end
  333. end
  334. mod
  335. module ${ModuleName}
  336. ${cursor}
  337. end
  338. mod
  339. module ${ModuleName}
  340. module_function
  341. ${cursor}
  342. end
  343. mrc
  344. remove_column :${table}, :${column}
  345. ope
  346. open(${pipe}) { |${io}| ${cursor} }
  347. opt
  348. opts.on( "-${o}", "--${option}"${1},
  349. "${description}" ) do |${opt}|
  350. ${cursor}
  351. end
  352. optp
  353. require "optparse"
  354. require "ostruct"
  355. options = OpenStruct.new(${default})
  356. ARGV.options do |opts|
  357. opts.banner = "Usage: #{File.basename($$PROGRAM_NAME)} [OPTIONS]${1}"
  358. opts.separator ""
  359. opts.separator "Specific Options:"
  360. ${cursor}
  361. opts.separator "Common Options:"
  362. opts.on( "-h", "--help",
  363. "Show this message." ) do
  364. puts opts
  365. exit
  366. end
  367. begin
  368. opts.parse!
  369. rescue
  370. puts opts
  371. exit
  372. end
  373. end
  374. par
  375. partition { |${e}| ${cursor} }
  376. params
  377. params[:${id}]
  378. patfh
  379. File.join(File.dirname(__FILE__), *%w[${here}])
  380. Pn
  381. PStore.new(${file_name})
  382. ra
  383. render :action => "${action}"
  384. ral
  385. render :action => "${action}", :layout => "${layoutname}"
  386. ran
  387. sort_by { rand }
  388. rb
  389. #!/usr/bin/env ruby -w
  390. rcea
  391. render_component :action => "${index}"
  392. rcec
  393. render_component :controller => "${items}"
  394. rceca
  395. render_component :controller => "${items}", :action => "${index}"
  396. rdb
  397. RAILS_DEFAULT_LOGGER.debug "${message}"${cursor}
  398. rea
  399. redirect_to :action => "${index}"
  400. reai
  401. redirect_to :action => "${show}", :id => ${item}
  402. rec
  403. redirect_to :controller => "${items}"
  404. reca
  405. redirect_to :controller => "${items}", :action => "${list}"
  406. recai
  407. redirect_to :controller => "${items}", :action => "${show}", :id => ${item}
  408. rej
  409. reject { |${e}| ${cursor} }
  410. reject
  411. reject { |${element}| ${element}.${cursor} }
  412. rep
  413. results.report("${name}:") { TESTS.times { ${cursor} } }
  414. req
  415. require "${cursor}"
  416. reve
  417. reverse_each { |${e}| ${cursor} }
  418. rf
  419. render(:file => "${filepath}")
  420. rfu
  421. render(:file => "${filepath}", :use_full_path => ${false})
  422. ri
  423. render(:inline => "${hello}")
  424. ril
  425. render(:inline => "${hello}", :locals => { ${name} => "${value}"${4} })
  426. rit
  427. render(:inline => "${hello}", :type => ${rxml})
  428. rl
  429. render(:layout => "${layoutname}")
  430. rn
  431. render(:nothing => ${true})
  432. rns
  433. render(:nothing => ${true}, :status => ${401})
  434. ro
  435. attr_reader :${attr_names}
  436. rp
  437. render(:partial => "${item}")
  438. rpc
  439. render(:partial => "${item}", :collection => ${items})
  440. rpl
  441. render(:partial => "${item}", :locals => { :${name} => ${value} })
  442. rpo
  443. render(:partial => "${item}", :object => ${object})
  444. rps
  445. render(:partial => "${item}", :status => ${500})
  446. rt
  447. render(:text => "${render}")
  448. rtl
  449. render(:text => "${render}", :layout => "${layoutname}")
  450. rtlt
  451. render(:text => "${render}", :layout => ${true})
  452. rts
  453. render(:text => "${render}", :status => ${401})
  454. rw
  455. attr_accessor :${attr_names}
  456. sca
  457. scan(/${pattern}/) { |${match}| ${cursor} }
  458. sel
  459. select { |${e}| ${cursor} }
  460. select
  461. select { |${element}| ${element}.${2} }${cursor}
  462. session
  463. session[:${User}]
  464. sin
  465. class << self; self end
  466. sor
  467. sort { |a, b| ${cursor} }
  468. sorb
  469. sort_by { |${e}| ${cursor} }
  470. ste
  471. step(${2}) { |${n}|${cursor} }
  472. sub
  473. sub(/${pattern}/) { |${match}|${cursor} }
  474. tc
  475. require "test/unit"
  476. require "${library_file_name}"
  477. class Test${amp} < Test::Unit::TestCase
  478. def test_${case_name}
  479. ${cursor}
  480. end
  481. end
  482. tim
  483. times { |${n}|${cursor} }
  484. tra
  485. transaction${1} { ${cursor} }
  486. ts
  487. require "test/unit"
  488. require "tc_${test_case_file}"
  489. require "tc_${test_case_file}"
  490. uni
  491. ARGF.each_line${1} do |${line}|
  492. ${cursor}
  493. end
  494. unless
  495. unless ${condition}
  496. ${cursor}
  497. end
  498. until
  499. until ${condition}
  500. ${cursor}
  501. end
  502. upt
  503. upto(${0}) { |${n}|${cursor} }
  504. usai
  505. if ARGV.${1}
  506. puts "Usage: #{$$PROGRAM_NAME} ${ARGS_GO_HERE}"
  507. exit
  508. end
  509. usau
  510. unless ARGV.${1}
  511. puts "Usage: #{$$PROGRAM_NAME} ${ARGS_GO_HERE}"
  512. exit
  513. end
  514. va
  515. validates_associated :${attribute}
  516. vc
  517. validates_confirmation_of :${attribute}
  518. ve
  519. validates_exclusion_of :${attribute}
  520. verify
  521. verify :only => [:${1}], :session => :user, :params => :id, :redirect_to => {:action => '${index}'}
  522. verify
  523. verify :only => [:${1}], :method => :post, :render => {:status => 500, :text => "use HTTP-POST"}
  524. vl
  525. validates_length_of :${attribute}, :within => ${20}
  526. vp
  527. validates_presence_of :${attribute}
  528. vpif
  529. validates_presence_of :${attribute}, :if => proc { |obj| ${condition} }}
  530. vu
  531. validates_uniqueness_of :${attribute}
  532. when
  533. when ${condition}
  534. ${cursor}
  535. while
  536. while ${condition}
  537. ${cursor}
  538. end
  539. wo
  540. attr_writer :${attr_names}
  541. Yd
  542. File.open(${yaml}, "w") { |${file}| YAML.dump(${obj}, ${file}) }
  543. yields
  544. :yields: ${arguments}
  545. Yl
  546. File.open(${yaml}) { |${file}| YAML.load(${file}) }
  547. zip
  548. zip(${enums}) { |${row}| ${cursor} }