Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Ruby and Rails

  1. #1
    Married Mouth-breather JohnClay's Avatar
    Type
    INTP
    Join Date
    Dec 2013
    Posts
    2,001
    INTPx Award Winner

    Ruby and Rails

    I've started learning Ruby and Rails.... it is more complicated than some of the programming tasks that I have been avoiding at work... I started off doing free tutorials at http://www.codecademy.com/ and now I using http://teamtreehouse.com/ which costs $25 / month. I've been playing back the videos faster than normal - sometimes at double the normal speed.
    This is how to set it up on Mac OSX Yosemite:
    https://gorails.com/setup/osx/10.10-yosemite

    One thing I found interesting about Ruby is that you often don't need to "return" or output a variable...

    e.g.
    Code:
    def sum a, b
      a + b
    end
    <h1><%= sum 1, 2 %></h1>

    This should output
    <h1>3</h1>

    If you don't include the = sign it doesn't output the result.

    I haven't told my employer that I'm learning ruby yet. BTW my normal job involving PHP seems to be easier now that I am learning ruby.

    More Ruby examples:
    http://en.wikipedia.org/wiki/Ruby_%2...ge%29#Examples
    Last edited by JohnClay; 02-13-2015 at 09:50 AM.

  2. #2
    Mens bona regnum possidet ferrus's Avatar
    Type
    INTP
    Join Date
    Dec 2013
    Location
    Barcelona, Catalonia
    Posts
    5,669
    Quote Originally Posted by JohnClay View Post
    One thing I found interesting about Ruby is that you often don't need to "return" or output a variable...
    Erm, you're using a templating language, so that's not really surprising.
    Die Logik ist keine Lehre, sondern ein Spiegelbild der Welt. Die Logik ist transcendental. - Wittgenstein

  3. #3
    Married Mouth-breather JohnClay's Avatar
    Type
    INTP
    Join Date
    Dec 2013
    Posts
    2,001
    INTPx Award Winner
    Quote Originally Posted by ferrus View Post
    Erm, you're using a templating language, so that's not really surprising.
    Is PHP a templating language though? If it is then it usually requires "echo" to display something....

    Also in Ruby functions they often teach you to use "return" but it would still detect a correct answer if I didn't.....

  4. #4
    Married Mouth-breather JohnClay's Avatar
    Type
    INTP
    Join Date
    Dec 2013
    Posts
    2,001
    INTPx Award Winner
    It seems that embedded Ruby (.erb) is a templating language while regular Ruby isn't really. (?)

  5. #5
    Mens bona regnum possidet ferrus's Avatar
    Type
    INTP
    Join Date
    Dec 2013
    Location
    Barcelona, Catalonia
    Posts
    5,669
    To be more accurate you are using a templating engine. Most PHP applications will obviously use a templating engine also.
    Die Logik ist keine Lehre, sondern ein Spiegelbild der Welt. Die Logik ist transcendental. - Wittgenstein

  6. #6
    Married Mouth-breather JohnClay's Avatar
    Type
    INTP
    Join Date
    Dec 2013
    Posts
    2,001
    INTPx Award Winner
    But Php doesn't do what I'm talking about. Also irb does what I'm talking about and I don't think templating is involved with that.

  7. #7
    Married Mouth-breather JohnClay's Avatar
    Type
    INTP
    Join Date
    Dec 2013
    Posts
    2,001
    INTPx Award Winner
    Btw irb is a command line tool

  8. #8
    Now we know... Asteroids Champion ACow's Avatar
    Type
    INTP
    Join Date
    Dec 2013
    Location
    Melbourne, Australia
    Posts
    2,267
    Is it just because its lisp-y/expressiony?

    Which is to say, everything(or maybe most things in ruby) return a value, therefore there is no need for an explicit return?

    /i don't actually know ruby at all, so i don't know if that has anything to do with it. Just that in lisp there's only a couple of cases where you need a return-esque function, and i remember people saying ruby is rather lisp like but for mortals/regular people...

  9. #9
    Married Mouth-breather JohnClay's Avatar
    Type
    INTP
    Join Date
    Dec 2013
    Posts
    2,001
    INTPx Award Winner
    Quote Originally Posted by ACow View Post
    Is it just because its lisp-y/expressiony?

    Which is to say, everything(or maybe most things in ruby) return a value, therefore there is no need for an explicit return?
    This is using IRB (interactive ruby)

    puts "test"
    test
    => nil (returns nil)

    (1..5).each {|x| puts x }
    1
    2
    3
    4
    5
    => 1..5 (returns "1..5")

    Sometimes the value that is implicitly returned isn't useful so in that case in html you wouldn't use = (e.g. <% end %>)

    /i don't actually know ruby at all, so i don't know if that has anything to do with it. Just that in lisp there's only a couple of cases where you need a return-esque function, and i remember people saying ruby is rather lisp like but for mortals/regular people...
    What I like about Ruby is that there are many ways to do things and it is very compact and powerful. At first the code in the Wikipedia article was very hard to follow but I'm starting to master it. Then Rails lets you rapidly create web apps (once you master it)

    BTW there's also this:
    5.times {|x| print x}

    This prints: 01234 and returns 5.

    BTW in IRB and ruby you can get console input (gets) like in C and C++ and Java.

  10. #10
    Now we know... Asteroids Champion ACow's Avatar
    Type
    INTP
    Join Date
    Dec 2013
    Location
    Melbourne, Australia
    Posts
    2,267
    Just doing a quick web search, and it appears that yes, everything in Ruby is an expression.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •