Giter Site home page Giter Site logo

ruby-playground's Introduction

All kind of Ruby code snippet

About this repo

I copy & paste & modify & write code to learn Ruby.
Since this is not a tutorial. It may not really useful to you.

method

zip
each_with_index
each_slice
each_cons

1. set 用了 hash function 所以 include? 检查特别快

2. 把 false == x 放在左边和 x == false 是不一样的

前者是调用了 FalseClass#== method

3. Every value is true except false and nil.

4. If you need to differentiate between false and nil, either use the nil? method or use the “==” operator with false as the left operand. -- <Effective Ruby: 48 Specific Ways to Write Better Ruby> first chapter

5. ruby 里惯例用下划线 first_name 而不是 firstName 这种驼峰式写法

  • Variables: ** Local x
    • Instance @x
    • Class @@x
    • Global $x

Instance variables, which serve the purpose of storing information for individual objects, always start with a single at sign (@) and consist thereafter of the same character set as local variables—for example, @age and @last_name.

Class variables, which store information per class hierarchy (again, don’t worry about the semantics at this stage), follow the same rules as instance variables, except that they start with two at signs—for example, @@running_total.

Global variables are recognizable by their leading dollar sign ($)—for example, $population.

Constants begin with an uppercase letter. A, String, FirstName, and STDIN are all valid constant names.

There’s always a self defined when your program is running

$ ruby -cw c2f.rb
The -cw command-line flag is shorthand for two flags: -c and -w. The -c flag means check for syntax errors. The -w flag activates a higher level of warning: Ruby will fuss at you if you’ve done things that are legal Ruby but are questionable on grounds other than syntax.
print   no newline
puts    newline
p

Ruby facilitates this process with the 'require' and 'load' methods. We’ll start with load, which is the more simply engineered of the two.

Book

ruby-playground's People

Contributors

1c7 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.