Some hints on ruby methods

acts_like_string?()

name=”selva”

name.acts_like_string?() -> returns true.

capitalize()

name.capitalize

downcase()

name.downcase

titleize()

name.titleize

reverse()

name.reverse

ljust()

name.ljust(30) -> will insert 30 whitespaces on the right side of the ‘name’

rjust()

name.rjust(30) -> will insert 30 whitespaces on the left side of the ‘name’

lstrip()

name.lstrip() -> will remove the left hand side whitespaces

rstrip()

name.rstrip() -> will remove the right hand side whitespaces.

size()

name.size -> will returns the number of characters.

slize()

name.slize(5..10) -> will return the character which is in between from 5 to 10

split()

name.split(‘e’) -> will split the string “selva” into ‘s’ and ‘lva’

upcase()

name.upcase

acts_like_time?()

time=Time.now

time.acts_like_time? -> will return true



Advertisements