# Ruby code snippets : fibonacci series

One of the best ways to start learning Ruby is to try out simple programming problems. Let us see how we can generate fibonacci series using Ruby,

```# Generates a fixed length fibonacci series
class FibonacciGenerator

# print fixed number of fibonacci series numbers specified by size
def printFibo(size)
x1,x2 = 0, 1
0.upto(size){puts x1;x1+=x2; x1,x2= x2,x1} # note the swap for the next iteration
end

f = FibonacciGenerator.new
f.printFibo(10) # print first 10 fibo numbers

end
```

This is a verbose an example. You could achieve the same in a single line!

```
x1,x2 = 0, 1;  0.upto(size){puts x1;x1+=x2; x1,x2= x2,x1}

```
{"ft_lang_label":"__label__en","ft_lang_prob":0.66122866,"math_prob":0.95164174,"size":648,"snap":"2019-51-2020-05","text_gpt3_token_len":184,"char_repetition_ratio":0.14440994,"word_repetition_ratio":0.0,"special_character_ratio":0.2777778,"punctuation_ratio":0.15714286,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99744856,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-15T22:57:39Z\",\"WARC-Record-ID\":\"<urn:uuid:37f7d7e1-26d5-425c-8761-bdd00d317bcf>\",\"Content-Length\":\"16901\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:33e89d9c-715d-451e-97a5-630af0b65eae>\",\"WARC-Concurrent-To\":\"<urn:uuid:714bd025-844a-4d5e-8d46-a72b13a885e6>\",\"WARC-IP-Address\":\"208.113.169.202\",\"WARC-Target-URI\":\"http://www.rubytips.org/2007/12/29/ruby-code-snippets-fibonacci-series/\",\"WARC-Payload-Digest\":\"sha1:ENOVABAELOXAHHDAGDRQW7Q3GYWSNSEY\",\"WARC-Block-Digest\":\"sha1:6QIEAVW2WVNGAIBJNYHFWNI5CG63W7IQ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575541310970.85_warc_CC-MAIN-20191215225643-20191216013643-00188.warc.gz\"}"}