tag:blogger.com,1999:blog-6519389664379512676.post6925978280983794090..comments2023-08-05T11:14:48.311-03:00Comments on Ruby and Rails: Ruby, modulus operator and POLSMarcos Ricardohttp://www.blogger.com/profile/10175937289599328538noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-6519389664379512676.post-66158304730837083362013-05-03T06:03:25.894-03:002013-05-03T06:03:25.894-03:00The string interpolation with percent and percent ...The string interpolation with percent and percent operator are somewhat surprising to me (i think the importance of the operation is a bit exaggerated by assigning a separate and somewhat random operator to it).<br /><br />However, what is wrong with -5 % 3 being 1? It is the remainder of division of -5 by 3 (which is the unique number in the interval 0..2 congruent to -5 mod 3). Indeed:<br />Anonymoushttps://www.blogger.com/profile/04416785413351730207noreply@blogger.comtag:blogger.com,1999:blog-6519389664379512676.post-82813811385595044062009-02-01T11:43:00.000-02:002009-02-01T11:43:00.000-02:00Hi Ricardo, finally I understood the % concept. Th...Hi Ricardo, finally I understood the % concept. Thank you for your explanation!elefantehttps://www.blogger.com/profile/11363973156959154950noreply@blogger.comtag:blogger.com,1999:blog-6519389664379512676.post-72033348405417959522008-12-10T01:35:00.000-02:002008-12-10T01:35:00.000-02:00I have to say that this section has been frustrati...I have to say that this section has been frustrating to understand......but reading what you wrote has helped me a lot. Thanks! :)Sitout Bloghttps://www.blogger.com/profile/15996395876022502419noreply@blogger.comtag:blogger.com,1999:blog-6519389664379512676.post-18795876851285596012007-12-06T20:13:00.000-02:002007-12-06T20:13:00.000-02:00-5 mod 3 = 1 because -5 = 3(-2) + 1.-5 mod 3 = 1 because -5 = 3(-2) + 1.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6519389664379512676.post-44870929628014345402007-12-01T17:36:00.000-02:002007-12-01T17:36:00.000-02:00Thanks ste,That is the reason of this blog. To for...Thanks ste,<BR/><BR/>That is the reason of this blog. To force myself into Ruby thinking way.<BR/><BR/>Now I realize that I miss something on this Ruby translated formula:<BR/><BR/>r = ((a) - ((n) * ((a) / (n))))<BR/><BR/>It is not working with decimals.<BR/><BR/>Could You help ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6519389664379512676.post-7238676471466042672007-12-01T10:13:00.000-02:002007-12-01T10:13:00.000-02:00You have to keep in mind that in Ruby there are NO...You have to keep in mind that in Ruby there are NO operators... just method calls (or rather, messages) "masked" as operators (with the possible exception of the ternary ?: operator).<BR/>"abc" % 10 is just syntax sugar for "abc".%(10), just like 1 + 2 is equivalent to 1.+(2) and so on.<BR/>Given that, the truth is that you're NOT applying the "modulus" operator to a string, you're just calling aAnonymousnoreply@blogger.com