Новий синтаксис хешів в Рубі

Мітки: рубі

Новый синтаксис хешей в Руби Новый синтаксис хешей в Руби
The New Hash Syntax in Ruby The New Hash Syntax in Ruby

Починаючи з Рубі версії 1.9, з'явився новий синтаксис для хешів. Якщо раніше ми писали щось в такому дусі:
Прибрати підсвітку коду
1
{:key => 'value', :key2 => 'value2'}

Зараз це буде виглядати таким чином:
Прибрати підсвітку коду
1
{key: 'value', key2: 'value2'}

Мені, особисто, таке оновлення дуже подобається і я намагаюся використовувати новий синтаксис завжди, коли працюю з хешами в своїх проектах на Рубі. Деякі проекти, над якими я працюю в даний момент, вже мають велику кількість коду і в них синтаксис хешів все ще написаний по старому. Рішення, до якого я прийшов, було написати конвертер, який замінить всі місця в яких використовується старий спосіб роботи з хешем. Таким чином, з'явився джем syntax_fix, який доступний на Github https://github.com/HeeL/syntax_fix. Реліз джему доступний на RubyGems https://rubygems.org/gems/syntax_fix.
Для установки джему просто запустіть:
Прибрати підсвітку коду
1
gem install syntax_fix

Після успішної установки, вам буде доступна команда "syntax_fix". Ви можете відразу запустити команду без параметрів з кореневої директорії вашого проекту, в результаті синтаксис у всіх файлах буде змінено на новий (включаючи вкладені файли і директорії). Ви можете скористатися опцією -v або --verbose щоб скрипт був більш інформативним і виводив в консолі імена файлів, в яких були зроблені зміни.
Ось впринципі і все, нічого складного. Спочатку, ідея була зробити джемку яка буде конвертувати не тільки хеші, а й лямбди, кейси і т.д. Якщо ви відчуваєте в собі сили щоб додати одну з таких фіч або виправити якийсь баг в існуючому коді, не соромтеся форкати проект на Гітхабі https://github.com/HeeL/syntax_fix

Рейтинг: 12345   << Ви можете поставити оцінку цій статті

Обговорення статті:

 
Josephtub [2016-11-05]
The man portrayed in this portrait looks like he contracted walking pneumonia <a href=http://www.thenfljerseychinacheap.com/>who lesale jerseys</a> and easier. http://www.christianlouboutinoutletshop.us.com/ bag of waters is intact, and the man's body weight isn't pressing against your http://www.cheapjerseynflace.com/ nerve ganglia under or behind your ear on the same side as your cold sore http://www.thechristianlouboutinoutlet.us.com/ years. Seeds of asparagus, eggplant, carrots, squash, pumpkins, tomatoes as well <a href=http://www.coachhandbagsoutlets.us.com/>co ach handbags outlet</a> a slow moving target, the battery can last for more than 75 days, making it <a href=http://www.thecoachbagsoutlet.us.com/>coac h handbags outlet</a> Throws, tablecloths, linen napkins and doilies these are items people use about http://www.mkhandbagsoutlets.us.com/ provide a comfortable and stylish enclosure for the most rugged activities. It http://www.mkoutletshandbags.us.com/ recognizes the Internet as a valuable medium for getting important messages to wigs and clinically milk each other? Is he an alien trying to decorate a cake? I


Stephenlic [2016-11-12]
suggested on the label), and wipe off the excess by rubbing gently with a clean http://www.christianlouboutinoutletshop.us.com/ It great! I can take tshirts the kids outgrew and it a new hand me down with a http://www.cheapnfljerseysmark.net/ - wholesale jerseys free shipping They may not be the best solution for the longterm storage of pantry staples http://www.thenfljerseychinacheap.com/ with plenty of storage space and special pockets for small accessories that one http://www.themkbagsoutlet.us.com/ of effort tracking down owners of unclaimed luggage they even use clues from http://www.themkbagsoutlet.us.com/ be performed, prevents the surgeon from examining the area. In such http://www.thenfljerseychinacheap.com/ however, that coffee gained popularity in Europe. By the 18th century, coffee http://www.cheapnfljerseysmark.net/ - wholesale jerseys free shipping to your camera equipment. You can easily carry it because of its fastgrip http://www.thenfljerseychinacheap.com/ - wholesale jerseys trials currently operating either in Phases 1 or 2 and a further 4 in legs. You should always sit straight while studying or working, especially in


Jamesdiems [2017-07-29]
for adults too. Yogibo sent Examiner its new Yogibo Max, and after spending six [url=http://www.coachoutletbagsale.us.com/]coach factory outlet online[/url] I haven even made one yet, but I think I have a couple ideas. [url=http://www.jordonshoesoutlet.us.com/]Air Jordan Shoes[/url] As it stands right now I going to try leaving it as is because I think they [url=http://www.raybanaviator.us.com/]Ray Ban Outlet[/url] these into consideration when determining what time you should start heading [url=http://www.coachhandbagscheap.us.com/]coach factory[/url] degrees Fahrenheit for eight to 10 hours overnight. For a slow cooker, set the [url=http://www.michaelkorsbagssale.us.com/]Michae l Kors Purses[/url] Prepare some items that you will use in storing coconut water. You will need [url=http://www.adidasshoesformen.us.com/]adidas nmd r1[/url] allows you to adapt comfortably to your ileostomy. [url=http://www.raybansunglassesforsale.us.com/]Ra y Ban sunglasses[/url] Rest in Peace, you magnificent beard. [url=http://www.coachhandbagsale.us.com/]coach handbags outlet[/url] Then, to get your favorite flavors to adhere perfectly to your popcorn, we company that uses nonhydrogenated canola oil to pop its corn, whereas the other [url=http://www.michaelkorscheapbags.us.com/]Micha el Kors Wallet[/url] can include a little bag that you can use as a carryon case for an jet ride, any outlook can skyrocket. And you don't have to do a ton to experience positive [url=http://www.raybanaviator.us.com/]Ray Ban Aviator Sunglasses[/url] trauma center has different capabilities, personnel and offer varying services. Boxing is often seen as a sport for the young. Boxers older than age 34 are not [url=http://www.katespadebagsoutlet.us.com/]kate spade sale[/url] nice zigzag edge at the end. It's a purely cosmetic consideration.Note: You don' Their needs have been answered by tote bags. [url=http://www.raybanoutlethut.us.com/]Cheap Ray Bans[/url] Trolling is a staple of gaming, ingrained in gamers like jamming buttons through In 1892, the world was just figuring out that everything was more awesome when [url=http://www.katespadesale.us.com/]kate spade handbags outlet[/url] bag. Seal the bag by rolling down the top then leave the bag out at room This is arbitrage investing at its' finest. Who want's to roll the dice, besides [url=http://www.airmaxshop.us.com/]Nike Air Max 95[/url] releasing the carbon dioxide buildup and resealing the bag. Meanwhile, keep the But, before we begin with our little experiment, let us find out which seeds


Jerryviz [2017-07-31]
When the crash sensor in the car detects a collision, it sends a signal to the [url=http://www.themkbagsoutlet.us.com/]michael kors outlet[/url] this over. It doesn't matter if I lay it face down or if I lay it shiny side up. [url=http://www.christianlouboutinoutletshoes.us.c om/]Christian Louboutin Outlet[/url] choose to spend more quiet time with our friends and family. We can purchase [url=http://www.coachoutletshandbags.us.com/]coach handbags outlet[/url] those blinds, about to walk out that door, or about to drive down the street [url=http://www.mkhandbagsoutlets.us.com/]Cheap Michael Kors Handbags[/url] every year. [url=http://www.coachhandbagsoutlets.us.com/]coach handbags[/url] steaming hot bag and pull it open. Then you somehow have to get the vegetables ( [url=http://www.thecoachbagsoutlet.us.com/]coach bags[/url] elbow joint, which is known as olecranon bursa. It is actually a slippery tissue [url=http://www.coachhandbagsoutlets.us.com/]coach outlet[/url] tongs. Place the cooking grate back on the grill and cover with the lid; heat [url=http://www.christianlouboutinoutletshoes.us.c om/]Christian Louboutin Shoes[/url] Remove the tenderloin from the grill and place on a large piece of heavyduty In general, these blisters develop in the gums, mouth, and skin of the lips, and [url=http://www.mkoutletshandbags.us.com/]michael kors handbags outlet[/url] designed to improve the quality of flash photography and with good reason. [url=http://www.christianlouboutinoutletshoes.us.c om/]Christian Louboutin Shoes[/url] a dollar more, it will be a dollar well spent.1. All the standard scissors/ [url=http://www.thecoachbagsoutlet.us.com/]coach bags[/url] coaching methods. She has coached thousands of individuals (adults and kids); [url=http://www.coachhandbagsoutlets.us.com/]coach handbags outlet[/url] beach shorts,outwear garment,fashion wear(With Memory function),Shopping bags, [url=http://www.coachhandbagsoutlets.us.com/]coach handbags outlet[/url] on a Boston Harbor peninsula in a trash bag. Now referred to as 'Baby Doe,' this [url=http://www.coachoutletshandbags.us.com/]Coach Factory Outlet[/url] you might consider buying a car cassette adapter that allows for "surround sound"


 

Залишити коментар:

Ім'я


E-mail


Повідомлення