Last active
November 17, 2015 11:26
-
-
Save taichiman/a5251824050989c6bec7 to your computer and use it in GitHub Desktop.
cheetsheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some |
ruby text processing:
lib strscan
String
tr (str, str)
insert
strip - delete ' '
start_with?
squeeze - sub 2 chars
delete, #count - chars
concat - obj, int
chop, #chomp
test - file
gets - file ARGV
tap {} - return self
ascii_only?
id
sub - replacement, search
slice - search
scanf - scans string
block_scanf -
scan - matching
index - find first occurence
next
match
include
gsub
[] - search
[]= replace
lines - to_a
each_line
each_codepoint - char2integer
each_char
each_byte
chars
codepoints
bytes - set bytes
split
rpartition - split on parts
prepend
clear
select - interested example with state
scrub - replace code chars
ord
intern - to sym
codepoints
rjust, #ljust - format tab output
printf
pretty_inspect
p
format
center
eql?
equal?
File#pathmap
open
gets
ext
idioms:
loop do
print "Input: "
line = gets
break if !line or line =~ /^qQ/
# ...
end
select - interested example with state
ruby MAIN FLOW:
def do_at_exit(str1)
at_exit { print str1 }
end
at_exit { puts "cruel world" }
do_at_exit("goodbye ")
exit
File:
Dir
entries
foreach dir
FileUtils
copy_entry
copy_file
copy_stream
cp, copy
CLI Options:
http://ruby-doc.org/stdlib-2.2.0/libdoc/getoptlong/rdoc/GetoptLong.html
The GetoptLong class allows you to parse command line options similarly to the GNU getopt_long() C library call.
http://ruby-doc.org/stdlib-2.2.0/libdoc/optparse/rdoc/OptParse.html
OptionParser is a class for command-line option analysis. It is much more advanced, yet also easier to use, than GetoptLong, and is a more Ruby-oriented solution.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rexml:
open file:
Element:
each_element( xpath=nil ) {|Element| ...}
each_element_with_attribute( key, value=nil, max=0, name=nil ) {|Element| ...}
each_element_with_text( text=nil, max=0, name=nil ) {|Element| ...}
get_elements( xpath )
get_text(path = nil)
text( path = nil )
XPath:
each
first
match
Elements:
find element - []