Proc in Ruby

fullname = Proc.new { |fname, lname| "First Name: #{fname}\nLast Name: #{lname}" }
puts fullname.call("John", "Smith")

Extension methods in Ruby

class String
	def capAlternative
		tempStr = ""
		index = 0
		self.each_char do |c|
			if index % 2 == 0
				tempStr << c.capitalize
			else
				tempStr << c
			end
			index = index + 1
		end
		return tempStr
	end
end

puts "World of Warcraft".capAlternative

Palindrome in Ruby

Solution to Project Euler problem 4

def isPalindrome(s)
  i = 0
  j = s.length - 1
  
  while i < j
    if s[i] != s[j]
      return false
    end
    i = i + 1
    j = j -1
  end
  
  return true
end

max = 0
(100..1000).each do |i|
  (100..1000).each do |j|
    prod = i * j
    prodStr = prod.to_s
    if isPalindrome(prodStr) && prod > max
      max = prod
    end
  end
end

puts(max)