Question: EDITED\*\*

I've been trying to implement a back button for my ToDoList project.What I'm trying to make it do is on pressing the back button on my phone while the user is typing something in the Editable field which is in the second\_layout(Editable activity),he could go back to the MainActivity without passing data,therefore the first\_layout.I already have a method called saveClick() which basically passes the text input from the Editable field which is in second\_layout back to MainActivity(first\_layout).

This is the method itself.

```
     public void saveClick(View view) {
     String messageString = ((EditText) findViewById(R.id.text_message)).getText().toString();
    if (messageString.equals("")) {
    }
    else {
   Intent intent=new Intent();
   intent.putExtra(IntentCode.INTENT_MESSAGE_CODE,messageString);
   setResult(IntentCode.INTENT_RESULT_CODE,intent);
   finish();
    }

```

And this is the onActivityResult

```
    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == IntentCode.INTENT_RESULT_CODE)
    messageString = data.getStringExtra(IntentCode.INTENT_MESSAGE_CODE);
    toDoList.add(messageString);
    theAdapter.notifyDataSetChanged();

```

Answer: 
There is nothing builtin to ruby that would do this because the methods you're calling return the element, or raise an exception. If they returned the element or nil then the suggestion of Cary Swoveland to use `&.` would be the answer.

The critical thing to remember here is what you're actually trying to do. Since you're writing automated tests, you're (most likely) not trying to check whether or not the elements exist (tests should be predictable and repeatable so you should know the elements are going to exist) but rather just wait for the elements to exist before getting the text. This means what you really want is probably more like

```
def get_section_id
  wait_until_section_visible
  section.wait_until_top_visible
  section.top.wait_until_course_visible
  section.top.course.wait_until_section_id_visible
  return section.top.course.section_id.text
end

```

You can write a helper method to make that easier, something like

```
def get_text_from_nested_element(*args)
  args.reduce(self) do |scope, arg| 
    scope.send("wait_until_#{arg}_visible")
    scope.send(arg)
  end.text
end

```

which could be called as

```
def get_section_id
  get_text_from_nested_element(:section, :top, :course, :section_id)
end

```
Whilst this is a bit outdated, the fact that `&.` won't work here when it is the most elegant perhaps gives rise for this being a useful feature

If you can raise it on GH with a sample page where this would be useful then we could look at getting it introduced

Luke