Ruby Commands

Ruby Commands
Ruby Commands

Ruby Notes

=begin
#
# Last resort way to view the source of a rails Methods: (ex: link_to)
git clone http://github.com/rails/rails.git
cd rails
grep -r 'def link_to'
#
=end


gem list
# List all gems installed if no name given

gem list r
# List all gems that start with r


# 3 ways to run system command
# ----------------------------

# 1) Using readlines
getDate = IO.popen("date")
readDate = getDate.readlines
print readDate

# 2) Using system()
system("date")
#system("tar xzf test.tgz")

# 3) Using backticks
result = `date`
print result



# Concatenate
# -----------

v = 'one' << 'two' << 'three'
print 'v = ' << v

w = 'one' + 'two' + 'three'
print 'w = ' +  w

x = "#{'one'}#{'two'}#{'three'}"
print "x = #{x}"

y = "one#{'two'}#{'three'}"
print "#{'y'} =  #{y}"

z = "onetwo#{'three'}"
print "z =  #{z}"


=begin
irb --simple-prompt
# Start irb with less cluttered prompt
=end

=begin
Weird looking multiline
comments in ruby
=end

# Single line comment

0.23 + 0.23
# 0 needs to be put in front to add .23 + .23

x="99".to_i
# Convert string to integer

print "pickle"
# Prints to the screen without a newline

puts "pickles"
# Prints to screen with a newline added; if not one already

p "please"
# Prints to screen as an inspect string

hungry = gets
# Use gets to grab input from keyboard and assign as variable


if hungry == "very"
puts "heres your pickle"
else
puts "not wasting any pickles on you!"
end
# Simple if statement; conditional blocks need to end with end

false;nil;true
# nil shows an absence of a result and will cause conditionals
# to fail.

# Types of variables: # local, instance, class, global
# Other identifiers are: constants, keywords, and method names

# Variables start with a-z or _ and consist of letters, underscores,
# and_or digits (convention is to use _ instead of camelCase
Previous
Next Post »

3 comments

Click here for comments
james
admin
4 April 2020 at 04:25 ×

https://blog.anidear.com/2011/11/convert-string-to-binary-in-ruby.html?showComment=1585945498992#c6403595534461941948

Reply
avatar
james
admin
4 April 2020 at 04:25 ×

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. purple amethyst ring

Reply
avatar
M. Taha
admin
11 April 2020 at 10:36 ×

Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It 's really very nice and Useful post.Thanks unique garnet rings

Reply
avatar