Console

irb

script:

#!/usr/bin/env ruby

Math

Math.sqrt
Math.sin

** : power

Method

def h(name = "world")
puts "hello #{name.capitalize}"
end

h "crhis"

General

puts
print

Class

class Greeter
	def initialize(name = "wokrd")
		@name = name
	end
	def sayhi
		puts "hi #{@name}"
	end
	def saybye
		puts "Bye #{@name}"
	end
end

g = Greeter.new("Pat")
g.sayhi
g.saybye

@name: instance variables

Check methods:

Greeter.instance_methods(false)


Published

08 June 2013

Tags