Is Ruby a functional language?

前端 未结 12 1497
谎友^
谎友^ 2021-01-30 04:09

Wikipedia says Ruby is a functional language, but I\'m not convinced. Why or why not?

12条回答
  •  粉色の甜心
    2021-01-30 04:26

    I most definitely think you can use functional style in Ruby.

    One of the most critical aspects to be able to program in a functional style is if the language supports higher order functions... which Ruby does.

    That said, it's easy to program in Ruby in a non-functional style as well. Another key aspect of functional style is to not have state, and have real mathematical functions that always return the same value for a given set of inputs. This can be done in Ruby, but it is not enforced in the language like something more strictly functional like Haskell.

    So, yeah, it supports functional style, but it also will let you program in a non-functional style as well.

提交回复
热议问题