Project

General

Profile

Feature #1122 ยป try.txt

rogerdpack (Roger Pack), 07/14/2012 03:04 PM

 
1
Feature #1122 [request for Object#try (guarded method invocation)]
2

    
3
Today:
4

    
5
>>  if entry.at('description') && entry.at('description').inner_text
6

    
7
or:
8

    
9
>> if (description = entry.at('description') && description.inner_text  
10

    
11
Proposal: Object#&& method:
12

    
13
  if entry.at('description').&&.inner_text
14

    
15
or alternate Proposal Object#andand or Object#present? or some other name:
16

    
17
  if entry.at('description').present?.inner_text
18
  
19
Pros: easier to read, no variable allocation.  Unknown cons.